fix: extend incremental-cache invalidation to css, html and asset source/inline modules#21108
Conversation
…t generators The incremental-cache fix for asset/resource (#21100) only flagged AssetGenerator, but CssGenerator, HtmlGenerator, AssetSourceGenerator and AssetBytesGenerator also derive their source types from incoming connections. A css module @imported from CSS and later imported from JS (or asset/source referenced from both) kept stale source types across incremental rebuilds, so the JS factory was missing and __webpack_require__ threw "Cannot find module". Override getTypesDependOnIncomingConnections() for those generators (HTML only when extract is auto). Add watch reproductions for css modules and asset/source.
🦋 Changeset detectedLatest commit: 93bc085 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 (5bec345). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@5bec345
yarn add -D webpack@https://pkg.pr.new/webpack@5bec345
pnpm add -D webpack@https://pkg.pr.new/webpack@5bec345 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21108 +/- ##
==========================================
+ Coverage 91.94% 91.98% +0.04%
==========================================
Files 581 581
Lines 61228 61236 +8
Branches 16700 16701 +1
==========================================
+ Hits 56295 56329 +34
+ Misses 4933 4907 -26
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:
|
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
152.5 KB | 330 KB | -53.78% |
| ❌ | Memory | benchmark "asset-modules-bytes", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
246 KB | 321.7 KB | -23.52% |
| ⚡ | Memory | benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
317.4 KB | 216.2 KB | +46.83% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/incremental-cache-source-types (93bc085) with main (3aba7a9)
Footnotes
-
18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
…remental cache Adds a watch case that builds an html module across an incremental rebuild with cacheUnaffected, exercising HtmlGenerator.getTypesDependOnIncomingConnections().
…er incremental cache Adds a watch case building an asset/bytes module referenced from CSS then JS across an incremental rebuild, exercising AssetBytesGenerator.getTypesDependOnIncomingConnections().
Summary
Follow-up to #21100 (fixes the remaining part of #20800). That PR fixed the incremental-cache staleness only for
AssetGenerator(asset/resource). Auditing everygetTypes()implementation showsCssGenerator,HtmlGenerator,AssetSourceGenerator(asset/source) andAssetBytesGenerator(asset/inline) also derive their source types from incoming connections, so they had the same bug: when such a module is not rebuilt but a new JS importer appears,moduleMemCaches2treated it as unchanged, reused the stale code generation, and__webpack_require__threwCannot find module. This overridesgetTypesDependOnIncomingConnections()for those generators (HTML only whenextractis auto, mirroring_shouldExtract).What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes —
test/watchCases/css/css-module-referenced-from-css-and-jsandtest/watchCases/css/asset-source-referenced-from-css-and-js(both fail without the fix withCannot find module).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?
n/a
Use of AI
AI (Claude) was used to audit the
getTypes()implementations, implement the generator flags, and write the watch reproductions; all results were reviewed and verified by running the tests.Generated by Claude Code