fix(enhanced): include duplicate shared fallback versions#4778
Conversation
🦋 Changeset detectedLatest commit: 71a6859 The changes in this PR will be included in the next version bump. This PR includes changesets to release 46 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/metro-plugin-rock
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/observability-plugin
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
Bundle Size Report10 package(s) changed, 31 unchanged. Package dist + ESM entry
Bundle targets
Consumer scenarios
Total dist (raw): 6.81 MB (+3.6 kB (+0.1%)) Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 71a685903f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const shareRequests = Array.from( | ||
| new Map( | ||
| (shareRequestsMap[shareName]?.requests || []).map( | ||
| ([request, version]) => [version, [request, version] as const], | ||
| ), | ||
| ).values(), | ||
| ); |
There was a problem hiding this comment.
Avoid racing per-version fallback builds
When collectInstalledSharedPackageVersions adds more than one version for a shared package, this list feeds the existing inner Promise.all that starts all fallback compilers for that same shareName concurrently. Each of those compilers writes to the same resolveOutputDir(outputDir, shareName) and createIndependentCompiler sets output.clean: true, so one version's emit can be deleted by another version's clean step; the duplicate-version case this change is meant to fix can still leave only the last fallback artifact on disk. Build the versions for a single shared package serially, or avoid cleaning the shared output directory per version.
Useful? React with 👍 / 👎.
What changed
Fixes #4748.
Shared tree-shaking fallback generation now supplements the collected root shared package with all installed versions of that same package from
node_modules, including pnpm's.pnpmstore layout. Fallback generation then de-duplicates by version so duplicate installed versions can each get a matching fallback artifact.Why
When a remote used
nanoid@3.3.11through a nested package while the root app hadnanoid@5.1.6, the manifest could point to3.3.11but only a5.1.6fallback was emitted. Runtime then failed because the matching fallback was missing.Validation
pnpm exec prettier --check packages/enhanced/src/lib/sharing/tree-shaking/CollectSharedEntryPlugin.ts packages/enhanced/src/lib/sharing/tree-shaking/IndependentSharedPlugin.ts packages/enhanced/test/unit/sharing/tree-shaking/CollectSharedEntryPlugin.test.ts .changeset/green-shared-fallbacks.mdpnpm --dir packages/enhanced exec rstest test/unit/sharing/tree-shaking/CollectSharedEntryPlugin.test.ts -c rstest.config.tspnpm --filter @module-federation/enhanced run buildpython3.12 .codex/skills/changeset-pr/scripts/run_changeset_status.py --verbosegit diff --checkI also ran the package lint path through the commit hook. It passed with existing package warnings.