next-federation
Deployment

Deploying an island remote on Vercel

Run an island remote on Vercel as static files plus one Vercel Function. Hosts reach it at the project's **production domain**, never at a generated deployment URL.

Deploy a remote to Vercel

The fixture test/fixtures/island-remote is a working example. One deployment holds one build.

Set the base to the production domain

Vercel provides the production domain, without the scheme, as VERCEL_PROJECT_PRODUCTION_URL.

vite.config.ts
nextFederationIslands({
  base: `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}/`,
  // ...
})

Do not use VERCEL_URL or any *-<hash>.vercel.app URL. Those URLs need a Vercel login, so browsers cannot load the island's assets from them.

Write the build script

Set it as buildCommand in vercel.json. It runs vite build, then:

  • copies dist/<build>/client/ to <outputDirectory>/b/<build>/, the build-pinned paths the envelope names;
  • writes dist/vercel/entry.js, which re-exports the build's rsc/index.js handler and buildId. The Function imports it statically, so Vercel bundles every server chunk.

Add the Function

api/nf.ts is a Web fetch export that calls the build's handler. A path pinned to another build (/b/<other>/_nf/...) gets 410 {"error":"NF-023"} with CORS *, as nf-serve answers for a retired build.

Configure routing and headers

Assets load cross-origin, so they need Access-Control-Allow-Origin.

vercel.json
{
  "framework": null,
  "installCommand": "",
  "buildCommand": "node scripts/vercel-build.ts",
  "outputDirectory": "dist/vercel/static",
  "rewrites": [
    { "source": "/_nf/:path*", "destination": "/api/nf" },
    { "source": "/b/:build/_nf/:path*", "destination": "/api/nf" }
  ],
  "headers": [
    {
      "source": "/b/:build/assets/:file*",
      "headers": [
        { "key": "Access-Control-Allow-Origin", "value": "*" },
        {
          "key": "Cache-Control",
          "value": "public, max-age=31536000, immutable"
        }
      ]
    }
  ]
}

Deploy

In a pnpm workspace, build on your machine or in CI and upload the output.

vercel link --project <project>
VERCEL_PROJECT_PRODUCTION_URL=<project>.vercel.app vercel build --prod
vercel deploy --prebuilt --prod

A prebuilt build has no VERCEL_PROJECT_PRODUCTION_URL, so set it as above. A build that Vercel runs sets it.

Good to know: The Vercel CLI writes VERCEL_OIDC_TOKEN to .env.local and .vercel/. Keep both out of git.

Know which path Vercel serves

PathServed by
/b/<build>/assets/*static output, with CORS * and immutable
/_nf/*the Function, through a rewrite
/b/<build>/_nf/*the Function: its own build only, else 410 NF-023
an earlier build's file404: a deployment holds only its own build

Handle skew after a deploy

Choose one of three options. The behaviour on Hobby is in the evidence notes.

Accept a short inert window

This works on every plan. After a deploy, a cached island stays inert until the host renders a fresh envelope: at most the host's island revalidate (60 seconds by default), or until an open tab navigates. Shorten it with revalidateIsland or revalidateTag('nf:<remote>') from a deploy hook.

Use Skew Protection (Pro and Enterprise)

Untested for islands. Islands are always cross-origin, and the library adds no deployment id to asset URLs, so treat this option as unproven.

Keep assets in persistent storage

Keep every build's /b/<build>/ files in storage that outlives a deployment, such as Vercel Blob or S3, and point base there. Add that origin to the remote's assetOrigins on the host. Cached pages of earlier builds still hydrate. Their build-pinned _nf paths answer 410. Untested.

Protect the deployment

  • Standard Protection (the default) protects generated URLs and leaves production domains public. Use it.
  • All Deployments also protects the production domain, so hosts cannot fetch envelopes. Do not use it.
  • Point the host's remotes config at the production domain. A generated URL answers 401 and the island shows its fallback.

Remove deployments after a security fix

Every earlier deployment keeps its own Function and dependencies. After you upgrade away from a react-server-dom-webpack affected by GHSA-xqc2-xf4c-x3h3, delete the affected deployments with vercel remove <deployment-url> or the dashboard. See NF-041.

Next steps

On this page