fix: await host init in dev for bridge SSR hydration entries#835
Merged
gioboa merged 2 commits intoJun 17, 2026
Merged
Conversation
…sts without index.html
commit: |
gioboa
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes a dev-only race when
hostInitInjectLocation: "entry"is used with SSR hosts that have no rootindex.html(Nitro, TanStack Start, etc.).Production builds already wrap hydration entries with
getBootstrapSource()(await initHost()before the client entry runs). In Vite dev (serve), hydration entry fallbacks only received a side-effectimportof the host-init module, sohydrateRootcould run before the Module Federation runtime finished initializing.This shows up most clearly with
@module-federation/bridge-react(createLazyComponent/loadRemote): bridge resolves the MF runtime synchronously on first render viagetInstance(). IfinitHost()has not completed, remotes fail on first paint with: "Module Federation runtime is not initialized"Production preview for the same apps works — the gap was dev-only client entry injection.
Affected setup
hostInitInjectLocation: "entry"index.htmlat dev time (or missing from project root)hydrateRoot,createRoot, orReactDOM.rendercommand: "serve"Typical frameworks: Nitro + React (
entry-client.tsx), TanStack Start (client.tsx+StartClient).React.lazy(() => import('remote/…'))with a route loader that pre-imports remotes may mask the same race; bridge should not require an app-levelawait hostInitPromiseshim.Root cause
In
pluginAddEntry.ts,isHydrationEntryFallbackmatches client hydration modules when rollup has no registered input entry. ForwaitsForInitinjections,usesDevEntryFallbackforced dev serve to prepend onlyimport hostInitinstead of the full bootstrap wrapper used inbuild.The old comment about SSR modules needing synchronous exports does not apply here — server entries do not match
isHydrationEntryFallback(no mount/hydrate calls).Nuxt dev is unchanged:
entry.async.jsis still skipped (skipNuxtDevEntryAsyncInject); host init is injected at mount time inentry.js.