fix(vite): preserve singleton:true packages in excludeSharedSubDependencies#681
Merged
gioboa merged 2 commits intomodule-federation:mainfrom May 3, 2026
Conversation
…encies The dev-mode heuristic that removes shared sub-dependencies to prevent initialization-order issues (e.g. lit/lit-html) was also silently removing packages explicitly declared with singleton:true such as react and react-dom when a company SDK or wrapper library lists them in its dependencies. This caused multiple React instances across host and remotes, breaking all hooks. Fix: add a singleton:true guard alongside the existing import:false guard. Closes module-federation#680
commit: |
gioboa
reviewed
May 2, 2026
Collaborator
gioboa
left a comment
There was a problem hiding this comment.
Thanks for your help @ThibautMarechal
I will look at this soonish
Contributor
Author
|
It fix my issue, but I don't know the impacts of other use cases. If you have another workarround, I can take it :) |
gioboa
approved these changes
May 3, 2026
Collaborator
gioboa
left a comment
There was a problem hiding this comment.
Thanks for this fix @ThibautMarechal 👏
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
Closes #680
excludeSharedSubDependenciesis a dev-mode heuristic that auto-removes shared packages that are sub-dependencies of other shared packages, to prevent initialization-order issues (e.g.litdepending onlit-html).However, the function was also silently removing packages explicitly declared with
singleton: true— such asreactandreact-dom— when a company SDK or wrapper library lists them in itsdependencies. This created multiple React instances across host and remotes, breaking all hooks withCannot read properties of null.The function already skips packages with
import: false. This PR adds the same guard forsingleton: true.Changes
src/plugins/pluginProxySharedModule_preBuild.ts— one-line fix: addsingleton === trueguard inexcludeSharedSubDependenciessrc/plugins/__tests__/pluginProxySharedModule_preBuild.test.ts:'excludes shared sub-dependencies in dev mode and warns'test: change lit sub-packages fromsingleton: true→singleton: false(they were usingsingleton: truebut asserting removal, which would now fail correctly)'preserves singleton: true shared sub-dependencies in dev mode without warning'— asserts react/react-dom are NOT removed when a wrapper lib lists them as deps'still removes non-singleton sub-dependencies when sibling singletons are preserved'— asserts the original lit-style behavior is preserved for non-singleton sub-deps.changeset/lucky-lions-rest.md— patch changesetTest plan
pnpm test)pnpm typecheck)pnpm fmt.check)