fix: make asset modules available in JS when referenced from CSS and lazy JS#20801
fix: make asset modules available in JS when referenced from CSS and lazy JS#20801alexander-akait merged 1 commit intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 89e943d 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 (5f0874b). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@5f0874b
yarn add -D webpack@https://pkg.pr.new/webpack@5f0874b
pnpm add -D webpack@https://pkg.pr.new/webpack@5f0874b |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20801 +/- ##
=======================================
Coverage 91.40% 91.41%
=======================================
Files 561 561
Lines 55364 55367 +3
Branches 14604 14604
=======================================
+ Hits 50605 50612 +7
+ Misses 4759 4755 -4
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:
|
Merging this PR will degrade performance by 32.14%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "asset-modules-source", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
264.9 KB | 390.3 KB | -32.14% |
| ⚡ | Memory | benchmark "lodash", scenario '{"name":"mode-development","mode":"development"}' |
5.3 MB | 4.1 MB | +28.94% |
| ❌ | Memory | benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' |
7.6 MB | 9.7 MB | -21.04% |
| ❌ | Memory | benchmark "concatenate-modules", scenario '{"name":"mode-development","mode":"development"}' |
711.1 KB | 967.3 KB | -26.49% |
Comparing fix/css-lazy-asset-resource (89e943d) with main (5c43068)
|
@alexander-akait You're right — we were clearing _sourceTypes too early, which could be a breaking change for custom plugins that rely on module.getSourceTypes() returning stable values during the compilation pipeline. We've revised the approach: instead of adding invalidateReuse() to the Module base class and clearing the cache in Compilation.js, we now clear _sourceTypes directly inside NormalModule.updateHash() |
alexander-akait
left a comment
There was a problem hiding this comment.
Not related directly, but I think we have a bug here too -
webpack/lib/css/CssGenerator.js
Line 697 in 2969fec
CssModuleGeneratorOptions and so changing namedExport to true or false maybe not change hash (not sure, but I don't find logic related to this), so will be great to investigate this too, thanks
|
Yeah, I noticed that too. I’ll follow up with another PR to review and fill in any missing generator cases. |
|
@xiaoxiaojx Thank you! |
|
@xiaoxiaojx let's rebase, thanks |
2969fec to
3239429
Compare
…lazy JS When an asset module is referenced from both CSS (via url()) and a lazy JS chunk (via lazyCompilation), the module was missing from the JS context at runtime. Root cause: NormalModule._sourceTypes was cached after first computation and never invalidated when incoming connections changed. Additionally, source types were not included in the module hash, so the code generation cache was not invalidated when types changed.
3239429 to
89e943d
Compare
Summary
Fixes #20800
When an asset module is referenced from both CSS (via url()) and a lazy JS chunk (via lazyCompilation), the module was missing from the JS context at runtime.
Root cause: NormalModule._sourceTypes was cached after first computation and never invalidated when incoming connections changed. Additionally, source types were not included in the module hash, so the code generation cache was not invalidated when types changed.
Fix:
What kind of change does this PR introduce?
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
Use of AI
Partial