Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 37 ยท Previews and Teams

Preview Deployments

Every pull request and branch gets its own live URL. Learn how preview and deploy-preview URLs work, comments and review tools, protecting previews, branch subdomains and preview data safety.

The feature that makes people fall in love with both platforms is the preview deployment: push a branch or open a pull request and, within a minute or two, you get a complete, working copy of the site at its own URL. Reviewers click a link instead of checking out code. Designers can judge the real page, and testers can try a change before it touches production.

The platforms cannot run here, so there are no screenshots or captured output. Behavior is described from documentation. The runnable code is a JavaScript stand-in for URL naming and access rules.

What creates a preview

  • Vercel: every push to a branch that is not the production branch makes a Preview deployment. Each commit gets a unique URL (for example project-abc123-team.vercel.app) plus a stable branch URL (like project-git-feature-login-team.vercel.app) that always points at the latest commit of that branch.
  • Netlify: pull requests make Deploy Previews (URL like deploy-preview-42--my-site.netlify.app), and non-production branches can make Branch deploys (feature-login--my-site.netlify.app) if enabled. Each individual deploy also has a permanent URL containing its deploy ID.

Both post the link back to your Git host: a status check on the commit and, usually, a comment on the pull request. Unique per-commit URLs never change, so you can paste one into a bug report and it will still show that exact version later.

flowchart LR
  A["Push to feature branch"] --> B["Platform builds the commit"]
  B --> C["Unique preview URL"]
  C --> D["Link posted on the pull request"]
  D --> E["Reviewers test and comment"]
  E --> F["Merge to main"]
  F --> G["Production deployment"]

Each push repeats steps A to D, so the preview always matches the latest code.

Reviewing with previews

Vercel can show a toolbar on previews so team members can leave comments pinned to elements, check feature flags and share the page; the comments sync with the project. Netlify offers Netlify Drawer for collaboration on deploy previews (comments, screenshots and a way to share feedback). Even without those, a preview link plus a screen recording in the PR is already a big improvement over "works on my machine". Typical team rules:

  1. No merge without a preview that someone other than the author has opened.
  2. UI changes include a preview link in the PR description.
  3. Automated checks (links, Lighthouse, end-to-end tests) run against the preview URL.

Previews are public unless you protect them

A preview URL is hard to guess, but it is not secret. If a branch contains unreleased content, protect it:

  • Vercel Deployment Protection: require a Vercel login (team membership), a password (paid), or share via signed "shareable links". Production can remain public while previews require login.
  • Netlify: password protection and visitor access controls (plan dependent) for deploy previews; some sites use Basic Auth through edge functions.
  • Always set X-Robots-Tag: noindex on previews so they never appear in search results. Both platforms add noindex headers to preview deployments by default, but verify it (Response Headers and Security).

Previews and data

Previews run your real build and functions, so they can call your real services. That is dangerous: a test checkout on a preview must not charge a live card, and a preview must not write to the production database. Configure environment variables per environment: preview deployments should get test API keys and a separate (or branched) database. Many database providers can create a copy-on-write branch per preview automatically through their platform integration. See Databases from Serverless.

Naming previews

Branch URLs include a sanitized branch name. Hostname labels have rules: lowercase letters, digits and hyphens, at most 63 characters. Longer branch names are truncated, usually with a short hash, so URLs stay unique. The stand-in imitates the idea (the exact algorithm is the platforms' own).

JS Preview URL stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

An access-rule model

Protection settings boil down to rules evaluated per request. This stand-in decides whether a visitor may see a deployment, given its environment and what they present. It teaches the logic, not the platforms' actual API.

JS Preview access stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Troubleshooting previews

  • Works locally, fails on the preview: a missing environment variable for the Preview environment is the usual cause.
  • Preview shows old content: you may be on a per-commit URL; use the branch URL for the latest.
  • No preview created: forked pull requests often do not get environment secrets for safety, and branches can be excluded in settings.
  • Preview calls the wrong API: a hard-coded production URL. Read it from an environment variable.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a stable branch URL do compared with a per-commit URL?

    Per-commit URLs are immutable; the branch URL moves forward with each push.
  2. 2. Why should previews use separate environment variables from production?

    Previews run real code, so without separate test credentials they could modify production data.
  3. 3. Which statement about preview URLs is true?

    Unguessable is not the same as access controlled. Use deployment protection or passwords when needed.
  4. 4. A hostname label may be at most how long?

    DNS labels are limited to 63 characters, which is why long branch names are shortened.

Summary

  • Every branch or pull request gets its own live URL; each commit has an immutable one.
  • Links are posted to the pull request for review, with comment tools on both platforms.
  • Previews are public unless you add protection; keep them out of search results.
  • Give previews test credentials and separate data.
  • Missing preview-scoped variables are the most common preview bug.

Next: Teams and Permissions