Skip to content

docs: defer remote hydration with <Hydrate> and use loaded-first in the Vite host - #39

Open
dmchoi77 wants to merge 2 commits into
module-federation:mainfrom
dmchoi77:docs/hydrate-remotes
Open

dmchoi77 wants to merge 2 commits into
module-federation:mainfrom
dmchoi77:docs/hydrate-remotes

Conversation

@dmchoi77

@dmchoi77 dmchoi77 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Summary

TanStack Start 1.169 added <Hydrate>, which keeps server-rendered markup and loads a component's code only when a trigger fires (for example, when it scrolls into view). We checked whether it works with remotes, and it does without adapter changes: the server still renders the remote inline, and the browser loads the remote's code after the trigger.

One condition applies. With Module Federation's default version-first share strategy, a host loads every remote's manifest and entry at startup, so <Hydrate> can defer only the exposed module's chunks. The Vite example host was the only host still on that default, so this PR switches it to loaded-first and documents how to use <Hydrate> with remotes. No package code changes.

Changes

1. Use loaded-first in the Vite example host

apps/vite-host had no shareStrategy, against the README's own advice. It now matches both Rsbuild hosts. The README also said one offline remote "fails the whole page" under version-first, which is true for Rsbuild hosts but not for the Vite host. It now describes each host. Measured with production builds and one remote offline:

Host version-first loaded-first
Rsbuild host Every remote slot stays loading Only the offline remote falls back
Rsbuild SSR host Every request answers 500 Only the offline remote falls back
Vite host Only the offline remote falls back, 14–17 console errors Only the offline remote falls back, 2–5 console errors

2. Document deferring remote hydration

A new README section, "Deferring remote hydration", with an example and these notes:

  • Share strategy: with loaded-first, only the remotes' stylesheets load before the trigger.
  • Loader: after a client-side navigation the loader runs in the browser, so preload() would load the remote right away. Preloading only on the server keeps SSR inline and defers it in the browser.
  • Prefetching: a strategy passed as prefetch loads only the host's code-split chunk. A function that calls preload() loads the remote; visible() ignores functions.
  • Inside a remote: exposed modules can use <Hydrate>. The adapter compiles both the browser build and the server container with Start's transform.

It also adds a known limitation. In development, an Rsbuild host cannot server-render a Vite remote that imports @tanstack/react-start, because the Node entry loader resolves @tanstack/router-core subpaths to the package's main entry. A follow-up PR will fix it and remove the note.

Validation

  • format:check, lint, typecheck: passed
  • test:core: 92/92
  • test:e2e with the Vite host on loaded-first: 23/23 (production 11, development 12)
  • The README example was type-checked in apps/vite-host.

@pkg-pr-new

pkg-pr-new Bot commented Dec 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/module-federation/tanstack/@module-federation/tanstack@39

commit: c40d781

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant