fix: stable shared module ids and runtime-chunk emission order#20860
Conversation
🦋 Changeset detectedLatest commit: 22899cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
Pull request overview
This PR fixes nondeterministic Module Federation output that can cause runtime and entry bundle content-hashes to drift between otherwise-identical builds (especially when absolute project roots differ across CI runners).
Changes:
- Make
ProvideSharedModule.identifier()path-normalizable bymakePathsRelativevia|-separated segments. - Emit
ConsumeSharedRuntimeModule’s consume-shared module lists in stable, id-sorted order usinggetOrderedChunkModulesIterableBySourceType(..., compareModulesById(...)). - Add targeted tests: a unit test for identifier normalization and a config-case asserting stable runtime mapping order.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/sharing/ProvideSharedModule.js |
Switch identifier delimiter to ` |
lib/sharing/ConsumeSharedRuntimeModule.js |
Use ordered chunk-module iteration with an id comparator to stabilize runtime emission order. |
test/SharingUtil.unittest.js |
Add unit coverage ensuring makePathsRelative produces stable identifiers across differing build roots. |
test/configCases/sharing/consume-shared-stable-runtime/* |
Add a config case validating that moduleToHandlerMapping is emitted in sorted id order (and runtime/main bundles execute). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #20860 +/- ##
===========================================
- Coverage 91.45% 79.62% -11.83%
===========================================
Files 562 522 -40
Lines 55490 53614 -1876
Branches 14656 14167 -489
===========================================
- Hits 50746 42689 -8057
- Misses 4744 10925 +6181
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks |
|
This PR is packaged and the instant preview is available (f08f19a). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@f08f19a
yarn add -D webpack@https://pkg.pr.new/webpack@f08f19a
pnpm add -D webpack@https://pkg.pr.new/webpack@f08f19a |
|
Of note, this seems to have broke downstreams using older versions of DetailsWe are not confident enough to open the issue because probably we should just update |
|
@krassowski very strange, should not, can you create a small reproducible test repo, we will investigate |
|
@krassowski I see the problem, shorty - due to this https://github.com/webpack/webpack/pull/20860/changes#diff-3cba45872480f13cbdfebad2df98d03726db44829f8dfa74d985b2e4b59af40aR57, to be honestly internal Feel free to feedback |

Summary
Makes shared-module runtime output stable across builds.
ProvideSharedModule.identifier()now separates the request path with|somakePathsRelativecan strip the build root (previously, differing absolute paths across CI runners produced different module IDs).ConsumeSharedRuntimeModulenow emitsmoduleToHandlerMappingentries in id-sorted order viagetOrderedChunkModulesIterableBySourceType, instead of chunk-graph insertion order. Together these prevent spurious content-hash churn on otherwise-identical rebuilds. Fixes #20852.What kind of change does this PR introduce?
A fix.
Did you add tests for your changes?
Yes
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing that I am aware of
Use of AI
I used AI to help me with the tests.