TanStack
TanStack Start and TanStack Router apps build with Vite, so they use @module-federation/vite directly. A TanStack Start host can consume remotes on the server and in the browser: remote components are rendered into the SSR response and then hydrated.
A client-only TanStack Router app is a regular Vite app; follow the Vite guide. The rest of this page covers the TanStack Start setup.
Supports
- TanStack Start hosts with server-side rendering through Nitro
- Remotes built with Vite, such as a React library exposing components
- Shared singletons for
react,react-dom, and your own packages
Installation
Configure the remote
The remote is a regular Vite React app that exposes components:
Configure the TanStack Start host
Add federation() before tanstackStart():
Two settings matter for SSR:
hostInitInjectLocation: 'entry'injects the host initialization into the entry script. TanStack Start has noindex.html, and this makes sure the federation runtime is ready beforehydrateRootruns.nitro.traceDepskeeps React and the federation runtime as Node externals in the Nitro server bundle. Without it, Nitro bundles React inline and the remote ends up with a different React instance, which breaks hooks and context.
Load remote components
Import remotes with React.lazy, and preload them in the route loader so the federation runtime resolves them on the server before rendering. Without the preload, the lazy component has not resolved yet during SSR and renders nothing.
Wrap remotes in an error boundary if the page should keep rendering when a remote is unavailable.
Declare remote modules so TypeScript can resolve them, or enable dts to download remote types automatically:
Examples
- TanStack host and remote: TanStack Start SSR host with a React 19 remote and a shared context package