GeezerVison is showing github.com — fix: make asset modules available in JS when referenced from CSS and lazy JS by xiaoxiaojx · Pull Request #20801 · webpack/webpack
Conversation
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:
- Add Module.invalidateSourceTypes() to clear cached source types when a module is not rebuilt but its connections may have changed
- Include source types in NormalModule.updateHash() so hash changes trigger code generation cache invalidation and HMR updates
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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
changeset-bot
Bot
commented
Apr 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xiaoxiaojx
changed the title
fix: make asset modules available in JS when referenced from CSS and …
fix: make asset modules available in JS when referenced from CSS and lazy JS
Apr 9, 2026
codecov
Bot
commented
Apr 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.41%. Comparing base (5c43068) to head (89e943d).
⚠️ Report is 15 commits behind head on main.
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
| Flag |
Coverage Δ |
|
| integration |
90.39% <100.00%> (+<0.01%) |
⬆️ |
| test262 |
41.97% <100.00%> (+<0.01%) |
⬆️ |
| unit |
36.23% <100.00%> (+<0.01%) |
⬆️ |
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
codspeed
Bot
commented
Apr 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Merging this PR will degrade performance by 32.14%
⚠️ Different runtime environments detected
Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.
Open the report in CodSpeed to investigate
⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 140 untouched benchmarks
⚠️ Please fix the performance issues or acknowledge them on CodSpeed.
Performance Changes
Comparing fix/css-lazy-asset-resource (89e943d) with main (5c43068)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
alexander-akait
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid we need to think about this fix more, adding invalidateReuse and call invalidateReuse is a potential breaking change...
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xiaoxiaojx reacted with thumbs up emoji
|
@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 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related directly, but I think we have a bug here too -
|
hash.update(/** @type {boolean} */ (this._esModule).toString()); |
, looks like we don't respect all 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xiaoxiaojx reacted with thumbs up emoji
|
Yeah, I noticed that too. I’ll follow up with another PR to review and fill in any missing generator cases.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xiaoxiaojx reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
xiaoxiaojx reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…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.
Types CoverageCoverage after merging fix/css-lazy-asset-resource into main will be
Coverage Report| File | Stmts | Branches | Funcs | Lines | Uncovered Lines |
|---|
| bin | | webpack.js | 98.77% | 100% | 100% | 98.77% | 91 | | examples | | build-common.js | 100% | 100% | 100% | 100% | | | buildAll.js | 100% | 100% | 100% | 100% | | | examples.js | 100% | 100% | 100% | 100% | | | template-common.js | 98.21% | 100% | 100% | 98.21% | 72 | | examples/custom-javascript-parser | | test.filter.js | 100% | 100% | 100% | 100% | | | examples/custom-javascript-parser/internals | | acorn-parse.js | 100% | 100% | 100% | 100% | | | meriyah-parse.js | 100% | 100% | 100% | 100% | | | oxc-parse.js | 91.30% | 100% | 100% | 91.30% | 140, 142–143, 145, 147, 153–154, 161, 168, 90 | | examples/markdown | | webpack.config.mjs | 100% | 100% | 100% | 100% | | | examples/typescript | | test.filter.js | 50% | 100% | 100% | 50% | 5 | | examples/virtual-modules | | test.filter.js | 100% | 100% | 100% | 100% | | | examples/wasm-bindgen-esm | | test.filter.js | 100% | 100% | 100% | 100% | | | examples/wasm-complex | | test.filter.js | 100% | 100% | 100% | 100% | | | examples/wasm-simple | | test.filter.js | 100% | 100% | 100% | 100% | | | examples/wasm-simple-source-phase | | test.filter.js | 100% | 100% | 100% | 100% | | | lib | | APIPlugin.js | 100% | 100% | 100% | 100% | | | AbstractMethodError.js | 100% | 100% | 100% | 100% | | | AsyncDependenciesBlock.js | 100% | 100% | 100% | 100% | | | AsyncDependencyToInitialChunkError.js | 100% | 100% | 100% | 100% | | | AutomaticPrefetchPlugin.js | 100% | 100% | 100% | 100% | | | BannerPlugin.js | 100% | 100% | 100% | 100% | | | Cache.js | 98.21% | 100% | 100% | 98.21% | 104 | | CacheFacade.js | 100% | 100% | 100% | 100% | | | CaseSensitiveModulesWarning.js | 100% | 100% | 100% | 100% | | | Chunk.js | 99.72% | 100% | 100% | 99.72% | 37 | | ChunkGraph.js | 100% | 100% | 100% | 100% | | | ChunkGroup.js | 100% | 100% | 100% | 100% | | | ChunkRenderError.js | 100% | 100% | 100% | 100% | | | ChunkTemplate.js | 100% | 100% | 100% | 100% | | | CleanPlugin.js | 98.72% | 100% | 100% | 98.72% | 206, 226, 382 | | CodeGenerationError.js | 100% | 100% | 100% | 100% | | | CodeGenerationResults.js | 100% | 100% | 100% | 100% | | | CommentCompilationWarning.js | 100% | 100% | 100% | 100% | | | CompatibilityPlugin.js | 100% | 100% | 100% | 100% | | | Compilation.js | 98.55% | 100% | 100% | 98.55% | 1559, 1855, 1862, 1870, 1892, 2788, 3213, 3868, 3897, 3950–3951, 3955, 3960, 3976–3977, 3991–3992, 3997–3998, 4471, 4497, 498, 503, 5205, 5286, 5301, 5326–5327, 5329, 5651, 5656, 5662, 5665, 5677, 5679, 5683, 5699, 5714, 5746, 5800, 5824, 5938, 717–718 | | Compiler.js | 99.56% | 100% | 100% | 99.56% | 1116–1117, 1125 | | ConcatenationScope.js | 98.59% | 100% | 100% | 98.59% | 189 | | ConcurrentCompilationError.js | 100% | 100% | 100% | 100% | | | ConditionalInitFragment.js | 100% | 100% | 100% | 100% | | | ConstPlugin.js | 100% | 100% | 100% | 100% | | | ContextExclusionPlugin.js | 100% | 100% | 100% | 100% | | | ContextModule.js | 100% | 100% | 100% | 100% | | | ContextModuleFactory.js | 97.75% | 100% | 100% | 97.75% | 258, 393, 418, 443, 447, 458 | | ContextReplacementPlugin.js | 100% | 100% | 100% | 100% | | | CssModule.js | 81.32% | 100% | 100% | 81.32% | 157, 162–177 | | DefinePlugin.js | 98.92% | 100% | 100% | 98.92% | 158–159, 175, 194, 268 | | DelegatedModule.js | 95.24% | 100% | 100% | 95.24% | 253–257 | | DelegatedModuleFactoryPlugin.js | 98.15% | 100% | 100% | 98.15% | 106 | | DelegatedPlugin.js | 100% | 100% | 100% | 100% | | | DependenciesBlock.js | 100% | 100% | 100% | 100% | | | Dependency.js | 98.13% | 100% | 100% | 98.13% | 371, 404 | | DependencyTemplate.js | 100% | 100% | 100% | 100% | | | DependencyTemplates.js | 100% | 100% | 100% | 100% | | | DllEntryPlugin.js | 100% | 100% | 100% | 100% | | | DllModule.js | 100% | 100% | 100% | 100% | | | DllModuleFactory.js | 100% | 100% | 100% | 100% | | | DllPlugin.js | 100% | 100% | 100% | 100% | | | DllReferencePlugin.js | 100% | 100% | 100% | 100% | | | DotenvPlugin.js | 97.88% | 100% | 100% | 97.88% | 237, 378, 391–392 | | DynamicEntryPlugin.js | 100% | 100% | 100% | 100% | | | EntryOptionPlugin.js | 100% | 100% | 100% | 100% | | | EntryPlugin.js | 100% | 100% | 100% | 100% | | | Entrypoint.js | 100% | 100% | 100% | 100% | | | EnvironmentNotSupportAsyncWarning.js | 100% | 100% | 100% | 100% | | | EnvironmentPlugin.js | 97.14% | 100% | 100% | 97.14% | 49 | | ErrorHelpers.js | 100% | 100% | 100% | 100% | | | EvalDevToolModulePlugin.js | 100% | 100% | 100% | 100% | | | EvalSourceMapDevToolPlugin.js | 100% | 100% | 100% | 100% | | | ExportsInfo.js | 100% | 100% | 100% | 100% | | | ExportsInfoApiPlugin.js | 100% | 100% | 100% | 100% | | | ExternalModule.js | 98.89% | 100% | 100% | 98.89% | 399–403, 542 | | ExternalModuleFactoryPlugin.js | 100% | 100% | 100% | 100% | | | ExternalsPlugin.js | 100% | 100% | 100% | 100% | | | FalseIIFEUmdWarning.js | 100% | 100% | 100% | 100% | | | FileSystemInfo.js | 99.49% | 100% | 100% | 99.49% | 182, 2213–2214, 2217, 2228, 2239, 2250, 278, 3596, 3611, 3635 | | FlagAllModulesAsUsedPlugin.js | 100% | 100% | 100% | 100% | | | FlagDependencyExportsPlugin.js | 98.74% | 100% | 100% | 98.74% | 399, 401, 405 | | FlagDependencyUsagePlugin.js | 100% | 100% | 100% | 100% | | | FlagEntryExportAsUsedPlugin.js | 100% | 100% | 100% | 100% | | | Generator.js | 100% | 100% | 100% | 100% | | | GraphHelpers.js | 100% | 100% | 100% | 100% | | | HarmonyLinkingError.js | 100% | 100% | 100% | 100% | | | HookWebpackError.js | 100% | 100% | 100% | 100% | | | HotModuleReplacementPlugin.js | 100% | 100% | 100% | 100% | | | HotUpdateChunk.js | 100% | 100% | 100% | 100% | | | IgnoreErrorModuleFactory.js | 100% | 100% | 100% | 100% | | | IgnorePlugin.js | 100% | 100% | 100% | 100% | | | IgnoreWarningsPlugin.js | 100% | 100% | 100% | 100% | | | InitFragment.js | 100% | 100% | 100% | 100% | | | InvalidDependenciesModuleWarning.js | 100% | 100% | 100% | 100% | | | JavascriptMetaInfoPlugin.js | 100% | 100% | 100% | 100% | | | LibManifestPlugin.js | 97.14% | 100% | 100% | 97.14% | 117, 120 | | LibraryTemplatePlugin.js | 100% | 100% | 100% | 100% | | | LoaderOptionsPlugin.js | 100% | 100% | 100% | 100% | | | LoaderTargetPlugin.js | 100% | 100% | 100% | 100% | | | MainTemplate.js | 100% | 100% | 100% | 100% | | | ManifestPlugin.js | 100% | 100% | 100% | 100% | | | Module.js | 98.50% | 100% | 100% | 98.50% | 1303, 1308, 1369, 1383, 1445, 1454 | | ModuleBuildError.js | 100% | 100% | 100% | 100% | | | ModuleDependencyError.js | 100% | 100% | 100% | 100% | | | ModuleDependencyWarning.js | 100% | 100% | 100% | 100% | | | ModuleError.js | 100% | 100% | 100% | 100% | | | ModuleFactory.js | 100% | 100% | 100% | 100% | | | ModuleFilenameHelpers.js | 98.85% | 100% | 100% | 98.85% | 106, 108 | | ModuleGraph.js | 99.73% | 100% | 100% | 99.73% | 1004 | | ModuleGraphConnection.js | 100% | 100% | 100% | 100% | | | ModuleHashingError.js | 100% | 100% | 100% | 100% | | | ModuleInfoHeaderPlugin.js | 100% | 100% | 100% | 100% | | | ModuleNotFoundError.js | 100% | 100% | 100% | 100% | | | ModuleParseError.js | 100% | 100% | 100% | 100% | | | ModuleProfile.js | 100% | 100% | 100% | 100% | | | ModuleRestoreError.js | 100% | 100% | 100% | 100% | | | ModuleSourceTypeConstants.js | 100% | 100% | 100% | 100% | | | ModuleStoreError.js | 100% | 100% | 100% | 100% | | | ModuleTemplate.js | 100% | 100% | 100% | 100% | | | ModuleTypeConstants.js | 100% | 100% | 100% | 100% | | | ModuleWarning.js | 100% | 100% | 100% | 100% | | | MultiCompiler.js | 99.69% | 100% | 100% | 99.69% | 645 | | MultiStats.js | 100% | 100% | 100% | 100% | | | MultiWatching.js | 100% | 100% | 100% | 100% | | | NoEmitOnErrorsPlugin.js | 100% | 100% | 100% | 100% | | | NoModeWarning.js | 100% | 100% | 100% | 100% | | | NodeStuffInWebError.js | 100% | 100% | 100% | 100% | | | NodeStuffPlugin.js | 100% | 100% | 100% | 100% | | | NormalModule.js | 97.79% | 100% | 100% | 97.79% | 1002, 1036, 1052, 1139, 1790, 1795–1805, 214, 726, 744, 761 | | NormalModuleFactory.js | 99.47% | 100% | 100% | 99.47% | 1067, 1376, 466, 478 | | NormalModuleReplacementPlugin.js | 100% | 100% | 100% | 100% | | | NullFactory.js | 100% | 100% | 100% | 100% | | | OptimizationStages.js | 100% | 100% | 100% | 100% | | | OptionsApply.js | 100% | 100% | 100% | 100% | | | Parser.js | 100% | 100% | 100% | 100% | | | PlatformPlugin.js | 100% | 100% | 100% | 100% | | | PrefetchPlugin.js | 100% | 100% | 100% | 100% | | | ProgressPlugin.js | 98.75% | 100% | 100% | 98.75% | 446–447, 452, 454, 518 | | ProvidePlugin.js | 100% | 100% | 100% | 100% | | | RawModule.js | 100% | 100% | 100% | 100% | | | RecordIdsPlugin.js | 100% | 100% | 100% | 100% | | | RequestShortener.js | 100% | 100% | 100% | 100% | | | RequireJsStuffPlugin.js | 100% | 100% | 100% | 100% | | | ResolverFactory.js | 100% | 100% | 100% | 100% | | | RuntimeGlobals.js | 100% | 100% | 100% | 100% | | | RuntimeModule.js | 100% | 100% | 100% | 100% | | | RuntimePlugin.js | 100% | 100% | 100% | 100% | | | RuntimeTemplate.js | 100% | 100% | 100% | 100% | | | SelfModuleFactory.js | 100% | 100% | 100% | 100% | | | SingleEntryPlugin.js | 100% | 100% | 100% | 100% | | | SizeFormatHelpers.js | 100% | 100% | 100% | 100% | | | SourceMapDevToolModuleOptionsPlugin.js | 100% | 100% | 100% | 100% | | | SourceMapDevToolPlugin.js | 99.16% | 100% | 100% | 99.16% | 267–268, 610 | | Stats.js | 100% | 100% | 100% | 100% | | | Template.js | 100% | 100% | 100% | 100% | | | TemplatedPathPlugin.js | 98.86% | 100% | 100% | 98.86% | 134–135 | | UnhandledSchemeError.js | 100% | 100% | 100% | 100% | | | UnsupportedFeatureWarning.js | 100% | 100% | 100% | 100% | | | UseStrictPlugin.js | 100% | 100% | 100% | 100% | | | WarnCaseSensitiveModulesPlugin.js | 100% | 100% | 100% | 100% | | | WarnDeprecatedOptionPlugin.js | 100% | 100% | 100% | 100% | | | WarnNoModeSetPlugin.js | 100% | 100% | 100% | 100% | | | WatchIgnorePlugin.js | 100% | 100% | 100% | 100% | | | Watching.js | 100% | 100% | 100% | 100% | | | WebpackError.js | 96.97% | 100% | 100% | 96.97% | 44 | | WebpackIsIncludedPlugin.js | 100% | 100% | 100% | 100% | | | WebpackOptionsApply.js | 100% | 100% | 100% | 100% | | | WebpackOptionsDefaulter.js | 100% | 100% | 100% | 100% | | | buildChunkGraph.js | 99.87% | 100% | 100% | 99.87% | 326 | | cli.js | 98.71% | 100% | 100% | 98.71% | 117, 469, 501, 543, 813 | | formatLocation.js | 100% | 100% | 100% | 100% | | | index.js | 100% | 100% | 100% | 100% | | | validateSchema.js | 94.67% | 100% | 100% | 94.67% | 100, 87, 89, 98 | | webpack.js | 97.22% | 100% | 100% | 97.22% | 196, 218, 220 | | lib/asset | | AssetBytesGenerator.js | 100% | 100% | 100% | 100% | | | AssetBytesParser.js | 100% | 100% | 100% | 100% | | | AssetGenerator.js | 100% | 100% | 100% | 100% | | | AssetModulesPlugin.js | 97.77% | 100% | 100% | 97.77% | 285, 309, 312, 364, 40 | | AssetParser.js | 100% | 100% | 100% | 100% | | | AssetSourceGenerator.js | 100% | 100% | 100% | 100% | | | AssetSourceParser.js | 100% | 100% | 100% | 100% | | | RawDataUrlModule.js | 100% | 100% | 100% | 100% | | | lib/async-modules | | AsyncModuleHelpers.js | 100% | 100% | 100% | 100% | | | AwaitDependenciesInitFragment.js | 100% | 100% | 100% | 100% | | | InferAsyncModulesPlugin.js | 100% | 100% | 100% | 100% | | | lib/cache | | AddBuildDependenciesPlugin.js | 100% | 100% | 100% | 100% | | | AddManagedPathsPlugin.js | 100% | 100% | 100% | 100% | | | IdleFileCachePlugin.js | 97.92% | 100% | 100% | 97.92% | 71, 83, 91 | | MemoryCachePlugin.js | 95.83% | 100% | 100% | 95.83% | 33 | | MemoryWithGcCachePlugin.js | 93.15% | 100% | 100% | 93.15% | 106, 113–114, 122, 89 | | PackFileCacheStrategy.js |
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|