Guides4 min read
Preview environments, done right
Developer Advocate
Preview environments change how teams review work. Instead of reading a diff and imagining the result, reviewers click a link and use the real thing. But getting previews right is harder than it looks.
A preview that behaves differently from production gives people false confidence. A preview connected to production data creates a much bigger problem. This guide covers the setup we recommend, and the mistakes we see most often.
Give every branch its own URL
A shared staging site works until two people need it at once. Then someone's change overwrites someone else's, and nobody is sure which version they're testing. Giving each branch its own environment removes the queue.
It helps to have two kinds of link. A branch URL always shows the latest push, so it belongs in the pull request. A deploy URL never changes, so it belongs in a bug report, where the reader needs to see exactly what you saw.
feat-checkout.shipr.dev # latest push to the branch
feat-checkout-a1f9c2e.shipr.dev # this exact deployProduction rules, not production data
A preview should behave exactly like production, with the same runtime, edge config and redirects, while pointing at safe, seeded data. Shipr does this with environment branches that inherit everything except secrets. A secret only reaches a preview if you explicitly mark it as preview-safe.
Leaving secrets out by default matters. If someone adds a production payment key and forgets about previews, the preview fails with a missing key. That's a little annoying, but it's much better than charging a real card during a design review.
Build seed data people can test with
An empty database makes every preview look broken, and one perfect record hides most layout bugs. Good seed data is small, predictable and a little awkward. Ours always includes:
- A new account with no activity, so reviewers see the empty states.
- A busy account with enough records to need pagination.
- Very long names, missing images and text in more than one script.
- One account for each role, so permissions are easy to check.
Create the data with a script that lives in your repository, and don't start from a copy of production. Names and email addresses aren't the only sensitive details: notes, attachments and unusual combinations of fields can identify someone too. Made-up data avoids that risk and is easier to reset.
Plan for external services
Your database is rarely the only thing a preview can affect. Go through each service your app calls and decide what it should do in a preview. Use test mode for payments, send email to a test inbox, and turn off scheduled jobs unless the branch is changing them.
Sign-in needs particular care. Many providers only allow redirects to addresses you've registered, and preview URLs change with every branch. A common fix is one fixed callback address that returns people to their preview. If you use one, only accept return addresses that belong to your project, or it could be used to send people anywhere.
Decide who can open a preview
A URL that's hard to guess isn't private. Links get forwarded, pasted into tickets and stored in browser histories. If a preview shows unreleased work, add a password, and make sure search engines can't index it. Password-protected previews are available on Pro and Team.
Comments where the work is
On Pro and Team, previews include an optional toolbar that lets designers and PMs pin comments to the exact element they're talking about. Comments sync back to the pull request, so developers don't have to piece together feedback from screenshots and chat threads.
- Pin comments to elements, not screenshots.
- Resolve threads from GitHub or from the page.
- Disable the toolbar per branch with one flag.
The best review comment is attached to the thing it's about.
Cleaning up after yourself
Previews are deleted automatically 14 days after their branch is merged or closed. You can pin important ones indefinitely. If your setup creates a database for each branch, delete it on the same schedule. Forgotten databases cost money, and they're easy to miss once the preview itself is gone.
A quick checklist
- Every pull request links to its own preview.
- Previews use production rules and made-up data.
- Secrets stay out unless they're marked as preview-safe.
- Payments, email and scheduled jobs can't affect real customers.
- Private work is password-protected, and old environments are removed.
If you're starting from a shared staging site, begin with the first three. They remove the queue and the biggest risks, and you can add the rest as more of your team starts reviewing in previews.