fix: invalidate incremental cache when CSS-only asset becomes JS-referenced#21100
Conversation
…renced Asset source types come from incoming origin module types (CSS vs JS), which moduleMemCaches2 did not track. A CSS-only asset later referenced from a lazily compiled JS chunk was treated as unchanged, so its cached CSS-only code generation was reused and __webpack_require__ threw at runtime. Track the asset origin-type signature in computeReferences so the cache is invalidated. Adds a hot test under incremental cacheUnaffected.
🦋 Changeset detectedLatest commit: 681c965 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 |
|
This PR is packaged and the instant preview is available (b0d3696). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@b0d3696
yarn add -D webpack@https://pkg.pr.new/webpack@b0d3696
pnpm add -D webpack@https://pkg.pr.new/webpack@b0d3696 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21100 +/- ##
==========================================
+ Coverage 91.81% 91.97% +0.15%
==========================================
Files 581 581
Lines 61163 61222 +59
Branches 16691 16695 +4
==========================================
+ Hits 56159 56309 +150
+ Misses 5004 4913 -91
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…rator Replace the hardcoded asset-type check in moduleMemCaches2 invalidation with a Generator.getTypesDependOnIncomingConnections() flag (true for assets), surfaced through Module/NormalModule. Add a deterministic watch test reproducing the incremental-cache variant of #20800 where a CSS-only asset becomes referenced from JS on a rebuild.
Merging this PR will not alter performance
Comparing Footnotes
|
Reuse Generator.getTypes() as the source of truth for the connection-dependent source types instead of re-collecting incoming origin types in Compilation. Module.getReferencedSourceTypes() recomputes fresh via the generator (bypassing the stale _sourceTypes cache) and returns the interned type set, so the chunk-graph reference cache can compare it by reference.
…ypes this.generator is always set during seal, matching getSourceTypes/getSize/updateHash.
Asset source types come from incoming origin module types (CSS vs JS),
which moduleMemCaches2 did not track. A CSS-only asset later referenced
from a lazily compiled JS chunk was treated as unchanged, so its cached
CSS-only code generation was reused and webpack_require threw at
runtime. Track the asset origin-type signature in computeReferences so the
cache is invalidated. Adds a hot test under incremental cacheUnaffected.