Semua artikel

Next Federation islands vs. remote components

The first question I'd ask when integrating a piece of UI is who owns the state it needs. A shared...

Tariq Khan (Open-Source)3 min read0 kali dilihat
Next Federation islands vs. remote components

The first question I'd ask when integrating a piece of UI is who owns the state it needs. A shared search box might need to call the host's search provider. A usage summary might need credentials held by another service. Next Federation offers a different integration for each case.

Use a remote component to read host context. Use an island for remotely rendered data and a separate React root.

Choose by where the UI needs to run

| | Island | Remote component | | --- | --- | --- | | Where server rendering happens | On the remote's server | On the Next.js host for a verified build | | React tree | Separate root in the browser | Part of the host's tree | | Props from the host | Plain JSON | Client-component props, including callbacks and children from client code | | Host React context | Stays in the host | Available through a shared context module | | Delivery | HTML, React Flight payload, and assets pinned to a build | Module Federation 2.0 module |

Architecture

When I'd use an island

I'd choose an island for a panel whose team owns the data and the server code that renders it. The host sends a request with JSON props. The remote renders its React Server Components and returns HTML, Flight data and the assets used to make it interactive. The host embeds the HTML and the browser hydrates a separate root.

That keeps the remote's data-fetching code on the remote server. It also means an uncached render needs a network round trip, and the page carries extra HTML and payload data. Plan CSS scoping yourself. For a private panel, decide whether to stream behind a fallback or wait and include the content in the first HTML. Island guide · Caching guide

When I'd use a remote component

I'd choose a remote component if it needs to work with a provider the host owns. The remote exposes a client component and the host loads it into its React tree. For context to work, the host and remote need the same module instance. Register the host's actual module and version, and let the remote declare a requiredVersion if it needs a particular API.

A verified build can also server-render in the Next.js host. Its server code runs with the host process's authority, so use a remote you'd trust as a dependency. Shared modules · Remote component integrity

Inspect both modes yourself

Run the advanced example, open the storefront, and turn on How is this page built? The overlay identifies which UI came from a remote, where it rendered, and whether it came in the first HTML or streamed in later. Look at the search UI in the federated header and the independently rendered product grid on the same page. That's the easiest way to see why the library supports two models. Advanced walkthrough


Sumber artikel open-source oleh Tariq Khan di DEV Community — Baca artikel asli. Topik: #nextjs #react #webdev #architecture

Ditulis & Dikurasi Oleh

Tariq Khan (Open-Source)

Software Engineer yang berfokus pada Next.js, TypeScript, arsitektur backend skalabel, Cloud, dan Applied AI.

Semua artikel

Komentar