Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

A remote just redeployed. What should the App Router hydrate?

A customer opens workspace settings on a slow connection. Next.js renders the usage panel from build 41. While the browser is loading JavaScript, the usage team promotes build 42. Build 42 changed the first thing the pan

A remote just redeployed. What should the App Router hydrate?

A customer opens workspace settings on a slow connection. Next.js renders the usage panel from build 41. While the browser is loading JavaScript, the usage team promotes build 42. Build 42 changed the first thing the panel renders.

If the browser asks for β€œthe latest panel” at that point, it can get build 42 for HTML that came from build 41. That's a frustrating kind of bug to investigate. The host hasn't changed, most reloads work, and the timing only lines up around a deploy.

Independent deploys are a big reason to keep Module Federation when moving off nextjs-mf. This is one part of how I built next-federation to support them in the App Router.

Next.js renders build 41. The remote promotes build 42 while the page loads. The browser still hydrates this page with build 41.

Resolve the build once per render

A remote component build publishes a descriptor that identifies the build and points to its versioned assets. The App Router host reads that descriptor and passes it to the remote component wrapper. The browser uses the descriptor for this render instead of independently asking which build is current. The host's cache policy determines when fresh renders see a newly promoted build. Host configuration

1. Next.js reads the descriptor for build 41.
2. The host renders the panel and passes that descriptor to its wrapper.
3. The remote promotes build 42.
4. The browser loads build 41 for the HTML it already has.

The build still needs to be available. If the remote deploy wipes the old asset directory, the browser has the right URL but there's nothing at the other end. Publish each build under its own versioned path, promote it after the files are available, and keep previous builds around for cached pages and open tabs. A rollback can move the pointer back to a previous build while leaving both sets of files available. Remote release guide

Decide what can run on the host

Build identity and SSR trust are separate decisions. For production SSR, the host verifies a signed or pinned descriptor and checks each server file against its recorded digest before evaluating it. An unsigned build may render in the browser if the host's policy permits. A failed verification can refuse the build altogether. I'd set a clear panel-level error state and actually open the host with a refused build once in staging. Remote component trust policy

Try a redeploy before you try a migration

The repo includes a local walkthrough that keeps a tab open while an island remote redeploys. It's a quick way to see two build versions coexist. To exercise the Module Federation component path described here, use two signed component builds in staging. Give each a different visible label, promote the second while a page from the first is still loading, and check the build IDs in the browser's network panel. The existing page should finish with the build it received. A fresh render can pick up the new build after the descriptor cache refreshes. Local walkthrough Β· Component release steps

If your micro-frontends already deploy independently, try this with the smallest widget you ship. I'd love to hear how long your team keeps old build assets and what determines that window. GitHub repository

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.