Island protocol v1
This is the wire contract between a host (an app that embeds islands) and a remote (a server that renders them). It is bundler-neutral: any server that...
This is the wire contract between a host (an app that embeds islands) and a remote (a server
that renders them). It is bundler-neutral: any server that implements it works with any host. The
reference codec is @next-federation/protocol.
Versioning
The protocol version is an integer major, carried as protocolVersion in every envelope. Adding
fields is compatible: a host keeps and ignores fields it does not know. Any change that removes or
reinterprets a field bumps the major. A host that receives an unknown major renders its fallback and
reports NF-003.
Island request
Endpoint: <base>/_nf/island/<island>, where <island> matches ^[A-Za-z][A-Za-z0-9_-]*$ and <base>
is the remote's absolute URL, optionally build-pinned (https://r.example/b/<buildId>). A server
takes the island name from the path segment after the last /_nf/island/.
GET <url>?p=<props>&h=<host>:pis base64url (no padding) of the canonical JSON of the props;his the same for the host context{ "basePath": string, "locale": string }.his omitted when the host context is{ "basePath": "", "locale": "" }.localeis the URL prefix segment,""for none or the default locale.- When
pwould be longer than 2048 characters the host sendsPOST <url>withcontent-type: application/jsonand the body{ "props": ..., "host": ... }, and noporhin the URL. - Canonical JSON has object keys sorted and no spaces or newlines, so equal props produce equal URLs
(cacheable). Props must be plain JSON: functions, symbols, bigints,
NaN/Infinity,Date,Map/Set, class instances and cycles are rejected (NF-009). Object properties whose value isundefinedare dropped. nullorundefinedprops are encoded as{}. A server decodes a missing or emptypas{}props and a missing or emptyhas{ "basePath": "", "locale": "" }.- Headers:
accept: application/json.Authorization: Bearer <jwt>only when the host has a token. Requests never carry cookies (credentials: 'omit').
Response envelope
A successful response is 200 with a JSON body:
| Field | Type | Meaning |
|---|---|---|
protocolVersion | 1 | Checked first. Anything else is NF-003. |
remote | string | The remote's own name. |
buildId | string | Build that rendered this envelope. |
mode | "development" or "production" | React mode of the rendering server. The client bundle must match (NF-006). |
html | string | Server-rendered markup of the island. No <script> or <link> tags. |
rscPayload | string | The island's Flight payload, for hydration. |
css | string[] | Absolute stylesheet URLs. |
bootstrap | string | Absolute URL of an ES module implementing the bootstrap contract below. |
reactVersion | string | React version of the remote's client bundle. |
idPlaceholder | string | Token present in html and rscPayload, matching ^[A-Za-z0-9_-]{4,}$ (non-empty; anything else is NF-004). The host replaces every occurrence with a per-mount prefix so one envelope can be mounted many times. |
Any missing or mistyped field, non-absolute bootstrap or css URL, or mode outside the union is
NF-004. A host checks that bootstrap and every css URL are on origins it allows for that
remote and are http(s), otherwise NF-005.
{
"protocolVersion": 1,
"remote": "shop",
"buildId": "v1",
"mode": "production",
"html": "<section id=\"nfid-1a2b3c4d-R1\"><h2>Widget</h2></section>",
"rscPayload": "0:[\"$\",\"section\",null,{\"id\":\"nfid-1a2b3c4d-R1\"}]\n",
"css": ["https://shop.example/b/v1/assets/panel-3f9a.css"],
"bootstrap": "https://shop.example/b/v1/assets/bootstrap-81c2.js",
"reactVersion": "19.3.1",
"idPlaceholder": "nfid-1a2b3c4d-"
}Per-mount identity
To mount, the host replaces idPlaceholder with idPlaceholder + <mountId stripped to [A-Za-z0-9]> + "-"
in html and rscPayload, and passes that same string as React's identifierPrefix. Two mounts of
one envelope therefore never share element ids.
Status codes
Every response carries Vary: Origin, Authorization. Every response to an allowed Origin carries
the CORS headers, including errors. Error bodies are {"error":"NF-0xx"}, except the 204 and the statuses that have no NF code (the bare 404, 405, 413 and 500), which have empty bodies.
Precedence. A server evaluates, in order: (1) GET /_nf/health, (2) OPTIONS, (3) the Origin
check, and only then the rows below, top to bottom. So health checks and preflights are answered
regardless of Origin. A preflight from a disallowed origin is a 204 without CORS headers, so the browser refuses it.
The bodies of 5xx responses never contain error messages.
| Condition | Status | Cache-Control |
|---|---|---|
GET /_nf/health (any base path of whole segments) | 200 ok | no-store |
OPTIONS | 204 | none |
Origin present and not allowed | 403 NF-022, no CORS headers | no-store |
path is not <base path>/_nf/island/<one segment> (whole segments; nothing after the name) | 404, empty body (no code) | no-store |
| method not GET/POST | 405 | no-store |
body larger than the server's limit (Content-Length or bytes read; default 65536 bytes, server-configurable) | 413 | no-store |
| island path whose name is empty or invalid, or props or host context are undecodable | 400 NF-004 | no-store |
| well-formed island name the server does not expose | 404 NF-021 | no-store |
| token malformed, expired, badly signed or with the wrong audience, or a private island requested with no token | 401 NF-014 | no-store |
| token whose issuer is not in the remote's issuer map | 401 NF-016 | no-store |
| signing keys unavailable | 503 NF-015, Retry-After: 5 | no-store |
| render failed, or a css/bootstrap URL is not absolute | 500 | no-store |
| build retired or unknown (build-pinned path) | 410 NF-023 | no-store |
| success, no token | 200 envelope | public, max-age=<maxAge> |
| success, token presented | 200 envelope | private, no-store |
Caching headers
Public responses are Cache-Control: public, max-age=60 by default. Any response to a request that
carried a token is private, no-store, so a shared cache never stores user-specific markup.
Bootstrap module contract
bootstrap is an ES module with one named export:
type IslandBootstrapModule = {
mountIsland(container: HTMLElement, options: MountIslandOptions): IslandHandle
}
type MountIslandOptions = {
envelope: { remote: string; buildId: string; mode: 'development' | 'production' }
rscPayload: string // already prefixed by the host
identifierPrefix: string // already computed by the host
bridge: { navigate(href: string): void; prefetch(href: string): void; basePath: string; locale: string }
getToken?: () => Promise<string | null>
onError?: (error: unknown, kind: 'uncaught' | 'caught' | 'recoverable') => void
}
type IslandHandle = {
update(next: { rscPayload: string }): void
destroy(): void
hydrated?: Promise<void> // resolves after the root's first commit
}The container already holds the server HTML; mountIsland hydrates it. destroy releases everything
the mount created. hydrated resolves once hydration has committed, so the island is interactive; a
host marks the island live only then. Updates sent before that are held, and only the newest is applied
once hydrated (an update during hydration would switch the root to client rendering). mountIsland
throws NF-012 on a container that already holds a live island root, so a container is never passed to
hydrateRoot twice. A bootstrap must be safe next to other remotes' bootstraps, and other builds of
the same remote, on one page: it keeps no state in shared globals except under a name that includes
its remote and build, and it never assumes it is the only React on the page.
Build pinning
Every URL in an envelope is absolute and build-pinned (<base>/b/<buildId>/assets/...), so an
envelope cached by a host keeps working for as long as that build is served. A build the remote has
retired answers 410 NF-023; the host then shows its fallback and refetches.
Identity
When a host sends a token it is a JWT in Authorization: Bearer, signed with ES256, with aud equal
to the remote's name. The host publishes its keys as a JWKS. The token is never placed in the URL or
body.
Server Actions
An island can call 'use server' functions exported by its remote. The browser posts directly to the
remote that rendered the island; the host is not involved.
Endpoint. POST <publicBase>_nf/action[?island=<name>], where <publicBase> is the build-pinned
base the island's bootstrap was served from (https://r.example/b/<buildId>/), so an action always
runs on the build that rendered its island. A server routes any path that ends in /_nf/action after
a base path of whole segments. The island query names the island making the call; it
must match ^[A-Za-z][A-Za-z0-9_-]*$.
Request.
X-NF-Action: <id>, the server reference id<file>#<export>. It must match^[A-Za-z0-9/_.@+-]{1,512}#[A-Za-z_$][A-Za-z0-9_$]{0,127}$and contain no..and no NUL. The custom header forces a CORS preflight, which a disallowed origin cannot pass.Content-Type: text/plain;charset=UTF-8ormultipart/form-data; boundary=...(what React'sencodeReplyproduces). Anything else is rejected, so a plain HTML form post orsendBeaconcall fails before any decoding.- Body: the action's arguments encoded with React's
encodeReply. Authorization: Bearer <jwt>only when the host has a token (see Identity). Requests never carry cookies (credentials: 'omit'); a server never readsCookiefor an action.
Response. 200 with Content-Type: text/x-component, Cache-Control: no-store and
Vary: Origin, Authorization. The body is a React Flight stream of { returnValue }, rendered with the
remote's React; host and remote must therefore run the same React version. If the action throws, the
response is still 200 and returnValue is a rejected promise (its message is redacted in
production); the server logs NF-033. The response updates nothing but the caller's promise: only the
calling island's root re-renders, from its own client state.
Check order. After health, OPTIONS and the Origin check (as for islands), a server evaluates
these rows top to bottom. Every response to an allowed Origin carries the CORS headers, including
errors; error bodies are {"error":"NF-0xx"}, the bare 405, 413 and 500 have empty bodies.
| Condition | Status |
|---|---|
| method is not POST | 405 |
X-NF-Action missing or malformed, island query invalid, or content type not allowed | 400 NF-032 |
island query names an island the server does not expose | 404 NF-021 |
body larger than the action limit (Content-Length or bytes read; default 1048576 bytes, server-configurable) | 413 |
| signing keys unavailable | 503 NF-015, Retry-After: 5 |
| token invalid, or whose issuer is not in the issuer map | 401 NF-014 / NF-016 |
island query names a private island and no token was sent | 401 NF-014 |
| no Server Action with this id in this build | 404 NF-031 |
| the action requires identity (per action, or remote-wide) and no token was sent | 401 NF-014 |
| the body cannot be decoded as action arguments | 400 NF-032 |
| the action ran (it returned or threw) | 200 Flight { returnValue } |
| the response stream could not be started | 500 |
| build retired or unknown (build-pinned path) | 410 NF-023 |
The identity requirement of each action is checked before its arguments are decoded. The island
gate is advisory: an action id is valid regardless of which island sends it, so a remote protects
data with a per-action identity requirement, not with the island name. Action ids are public: anyone
who can load the island can read them.
Bootstrap additions. A bootstrap that supports actions builds one action client per mount from
MountIslandOptions (all optional and additive):
type MountIslandOptions = {
// ...the fields above, plus:
envelope: { remote: string; buildId: string; mode: 'development' | 'production'; island?: string }
invalidateToken?: (rejected: string) => void // drop the cached token before a retry
onAction?: (report: ActionReport) => void // one call per action, after it settles
}
type ActionReport = { ok: boolean; status: number; code?: string; ms: number; retried: boolean }ActionReport never carries arguments, return values or tokens. When a request that carried a token
gets 401 NF-014, the bootstrap calls invalidateToken, asks getToken again and resends once, only
if the new token is non-null and different. It never retries NF-015, NF-016 or a 5xx. A non-200
response, or one that is not text/x-component, rejects the call with the response's NF code. When
it carries none: NF-031 for a 404, NF-032 for a 413, and NF-038 for anything else (a 5xx
from the remote or a proxy, another status, another content type, or no body).
The envelope may carry island (the rendered island's name, an optional string matching the island
name pattern); a host passes it through in MountIslandOptions.envelope.
Writing a remote without Vite
Serve GET /_nf/health, and GET/POST /_nf/island/<name> following the tables above. Render the
island to HTML and a Flight payload with any bundler, put a unique idPlaceholder in both, build a
browser module that exports mountIsland, and emit absolute build-pinned URLs for it and for the
stylesheets. @next-federation/protocol gives you decodeIslandRequest for the request side and
parseEnvelope to check what you produce.