next-federation

Live demo

Open five example apps on Vercel, three hosts and two remotes, and see islands and remote components work.

Try islands and remote components in a browser before you install anything. Five example apps run on Vercel, deployed from main: three hosts and two remotes.

Pick what to embed

  • Islands (vite-remote): the remote renders React Server Components on its server and sends HTML. The island keeps its own React.
  • Remote components (components-remote): the host loads the remote's client components into its own React tree and shares its context.
┌──────────────────────────────────────────────────────────────────┐
│ REMOTE  vite-remote (remote name "shop", Vite)                   │
│ serves islands: ProductPanel, Links, MyOrders                    │
└──────────┬──────────────────────┬──────────────────────┬─────────┘
           │ islands              │ islands              │ island
           ▼                      ▼                      ▼
┌────────────────────┐ ┌────────────────────┐ ┌────────────────────┐
│ HOST               │ │ HOST               │ │ HOST               │
│ next-app-router    │ │ next-pages-router  │ │ react-spa          │
│ ProductPanel       │ │ ProductPanel       │ │ ProductPanel       │
│ Links, MyOrders    │ │ Links, MyOrders    │ │                    │
│ CartButton         │ │ CartButton         │ │ CartButton         │
└────────────────────┘ └────────────────────┘ └────────────────────┘
           ▲                      ▲                      ▲
           │ remote               │ remote               │ remote
           │ component            │ component            │ component
┌──────────┴──────────────────────┴──────────────────────┴─────────┐
│ REMOTE  components-remote (remote name "cart", Vite)             │
│ exposes a remote component: CartButton                           │
└──────────────────────────────────────────────────────────────────┘
AppRoleEmbeds or servesLive
next-app-routerHostNext.js App Routerapp-router
next-pages-routerHostNext.js Pages Router, basePath: '/shop', en and frpages-router
react-spaHostVite SPA, browser onlyreact-spa
vite-remoteRemoteIslands ProductPanel, Links, MyOrders (private)vite-remote
components-remoteRemoteRemote component ./CartButtoncomponents-remote

Embedded pieces have a dashed outline. The sign-in is a demo: any name works.

Try the App Router host

Open the App Router host.

Click the island's buttons

vite-remote rendered the product panel on its server. The − and + buttons hydrate in your browser.

Add A1 to cart

This remote component runs on the host's React and shares its cart context, so the header count goes up.

The More products links navigate without a reload, so the cart count stays.

Open the private island

Open /orders and sign in with any name. The host signs a short-lived token, and vite-remote renders that name's orders.

Turn JavaScript off

Reload. The panel and the cart button remain, because the host rendered both on its server.

Try the other hosts

  • Pages Router. Open /shop/fr. The island links keep the basePath and locale. /shop/orders is the private island.
  • React SPA. The SPA fetches the island and the component in the browser, It has no server to sign tokens, so no private island.

Look at the remotes

Copy the source

Each app is a folder of examples/. Run all five with pnpm examples:dev.

Next steps

On this page