Skip to content

fix(optimize): reject concatenateModules with cacheUnaffected again - #22744

Merged
alexander-akait merged 1 commit into
mainfrom
fix/concatenation-cache-unaffected-guard
Oct 17, 2026
Merged

alexander-akait merged 1 commit into
mainfrom
fix/concatenation-cache-unaffected-guard

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

ModuleConcatenationPlugin is meant to refuse experiments.cacheUnaffected, the same way usedExports and mangleExports do. But it checked compilation.moduleMemCaches in the compilation hook, and that field is only set later, in _computeAffectedModules. So the check never fired, and watch mode could emit a broken bundle. The check now runs in optimizeChunkModules.

Found while checking the skipped WatchCacheUnaffectedTestCases. The cache/asset-concat watch case under cacheUnaffected, without its filter:

step 1
before runtime TypeError: __webpack_modules__[moduleId] is not a function
after optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect

Test filters:

  • cache/add-defines: filter removed; it passes under cacheUnaffected.
  • cache/asset-concat: comment added saying why it is filtered.
  • scope-hoisting/caching-inner-source and plugins/dll-reference-plugin: filtered the same way. They enable concatenation explicitly and were running this unsupported combination unnoticed.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes, in test/unitCases/Compiler.unittest.js. The new test fails without the fix. The watch-case filters are updated as above.

Does this PR introduce a breaking change?

No. The combination was already documented as unsupported; it now reports the error it was meant to.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Claude Code investigated the skipped tests, found the cause, wrote the fix and the test, and ran the watch, config and unit suites locally; I reviewed the change.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Builds using cacheUnaffected now report an error when module concatenation is enabled. The error is reported during module optimization rather than during compilation setup, while the incompatible combination remains unsupported.
    • Added coverage for this configuration and adjusted affected watch-test filtering.

@changeset-bot

changeset-bot Bot commented Oct 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4fa17b2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack Patch

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

@github-actions github-actions Bot added the area: optimization Tree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids) label Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (36f36bc).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@36f36bc
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@36f36bc
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@36f36bc

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: webpack/webpack/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 83fc82d7-2289-4b94-8a81-1d527dafd0e7
📥 Commits

Reviewing files that changed from the base of the PR and between 986efee and 4fa17b2.

📒 Files selected for processing: 6
  • .changeset/130-concatenation-cache-unaffected-guard.md
  • lib/optimize/ModuleConcatenationPlugin.js
  • test/unitCases/Compiler.unittest.js
  • test/watchCases/cache/asset-concat/test.filter.js
  • test/watchCases/plugins/dll-reference-plugin/test.filter.js
  • test/watchCases/scope-hoisting/caching-inner-source/test.filter.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

The module concatenation plugin now checks for cacheUnaffected during module optimization and reports the incompatibility through the hook callback. A compiler test, watch-case filters, and a changeset cover the behavior.

Changes: Concatenation cache guard

Layer / File(s) Summary
Check compatibility during module optimization
lib/optimize/ModuleConcatenationPlugin.js
The plugin moves the cacheUnaffected check to optimizeChunkModules. When module memory caches are present, it passes the incompatibility error to the hook callback and stops module optimization.
Test and document the incompatibility
test/unitCases/Compiler.unittest.js, test/watchCases/cache/asset-concat/test.filter.js, test/watchCases/plugins/dll-reference-plugin/test.filter.js, test/watchCases/scope-hoisting/caching-inner-source/test.filter.js, .changeset/130-concatenation-cache-unaffected-guard.md
The compiler test checks the error. Watch-case filters identify or exclude cases that require module concatenation. The changeset records the patch.

Suggested labels: area: optimization

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 4fa17

The incompatibility now produces a compilation error before assets are emitted in both run and watch builds. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Inconclusive The title uses valid Conventional Commit syntax, uses the allowed type fix, and accurately describes the change. The branch prefix is not provided, so that requirement cannot be verified. Provide the branch name or confirm that its prefix is fix. If it matches, the title passes this check.
Passed Passed checks: 3 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Types Coverage

Coverage after merging fix/concatenation-cache-unaffected-guard into main will be
99.22%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
bin
   webpack.js98.86%100%100%98.86%113
declarations
   WebpackOptions.ts99.94%100%100%99.94%4238
examples
   build-common.js100%100%100%100%
   buildAll.js100%100%100%100%
   examples.js100%100%100%100%
   template-common.js98.21%100%100%98.21%72
examples/custom-javascript-parser
   test.filter.js100%100%100%100%
examples/custom-javascript-parser/internals
   acorn-parse.js100%100%100%100%
   meriyah-parse.js100%100%100%100%
   oxc-parse.js100%100%100%100%
examples/markdown
   webpack.config.mjs100%100%100%100%
examples/module-federation
   test.filter.js100%100%100%100%
examples/reexport-components
   test.filter.js100%100%100%100%
examples/ssr
   test.filter.js100%100%100%100%
examples/typescript
   test.filter.js100%100%100%100%
examples/typescript-non-erasable
   test.filter.js50%100%100%50%5
examples/virtual-modules
   test.filter.js100%100%100%100%
examples/wasm-bindgen-esm
   test.filter.js100%100%100%100%
examples/wasm-complex
   test.filter.js100%100%100%100%
examples/wasm-emscripten
   test.filter.js100%100%100%100%
examples/wasm-simple
   test.filter.js100%100%100%100%
examples/wasm-simple-source-phase
   test.filter.js100%100%100%100%
lib
   Chunk.js100%100%100%100%
   Compilation.js98.67%100%100%98.67%1767, 2080, 2087, 2095, 2117, 2120, 23, 3099, 3636, 3679, 4268, 4272, 4399, 4420, 4545, 4582, 4589, 4642–4643, 4647, 4652, 4668–4669, 4683–4684, 4689–4690, 5214, 5240, 6070, 6087, 6105, 6121, 6136, 6161, 6164, 6532, 6535–6536, 6541, 6556, 6639, 6663, 843–844
   Compiler.js98.81%100%100%98.81%1116, 1153, 1156, 1336–1337, 1345, 848, 934, 975
   Dependency.js100%100%100%100%
   DependencyTemplate.js100%100%100%100%
   EntryPlugin.js100%100%100%100%
   Entrypoint.js100%100%100%100%
   ExternalsPlugin.js100%100%100%100%
   FileSystemInfo.js100%100%100%100%
   InitFragment.js100%100%100%100%
   LibraryTemplatePlugin.js100%100%100%100%
   ModuleFilenameHelpers.js100%100%100%100%
   ModuleNotFoundError.js100%100%100%100%
   MultiCompiler.js98.91%100%100%98.91%489, 561, 748, 813
   NormalModule.js100%100%100%100%
   NullFactory.js100%100%100%100%
   ProgressPlugin.js100%100%100%100%
   RawModule.js100%100%100%100%
   RequestShortener.js100%100%100%100%
   SingleEntryPlugin.js100%100%100%100%
   WebpackError.js100%100%100%100%
   index.js100%100%100%100%
   webpack.js98.59%100%100%98.59%306, 308
lib/asset
   AssetBytesGenerator.js100%100%100%100%
   AssetBytesParser.js100%100%100%100%
   AssetGenerator.js100%100%100%100%
   AssetModule.js100%100%100%100%
   AssetModulesPlugin.js98.45%100%100%98.45%335, 359, 362, 492, 59
   AssetParser.js100%100%100%100%
   AssetSourceGenerator.js100%100%100%100%
   AssetSourceParser.js100%100%100%100%
   RawDataUrlModule.js100%100%100%100%
   WebManifestGenerator.js100%100%100%100%
   WebManifestParser.js100%100%100%100%
lib/async-modules
   AsyncModuleHelpers.js100%100%100%100%
   AwaitDependenciesInitFragment.js100%100%100%100%
   InferAsyncModulesPlugin.js100%100%100%100%
   isGeneratorLowered.js100%100%100%100%
lib/bun
   BunTargetPlugin.js100%100%100%100%
lib/cache
   AddBuildDependenciesPlugin.js100%100%100%100%
   AddManagedPathsPlugin.js100%100%100%100%
   Cache.js96.49%100%100%96.49%10, 104
   CacheFacade.js100%100%100%100%
   IdleFileCachePlugin.js97.92%100%100%97.92%75, 87, 95
   MemoryCachePlugin.js92%100%100%92%33, 42
   MemoryWithGcCachePlugin.js93.42%100%100%93.42%106, 120–121, 130, 88
   PackFileCacheStrategy.js96.54%100%100%96.54%1306, 1406, 1410, 1472, 1718, 1802, 1825, 1855, 684, 703, 713–715, 717, 733–734, 739, 742, 744, 749, 754, 779, 785, 819, 825, 831, 836, 847, 856, 861–862, 864, 881, 887–888, 890
   ResolverCachePlugin.js100%100%100%100%
   getLazyHashedEtag.js100%100%100%100%
   mergeEtags.js100%100%100%100%
lib/config
   OptionsApply.js100%100%100%100%
   PlatformPlugin.js100%100%100%100%
   WebpackOptionsApply.js100%100%100%100%
   WebpackOptionsDefaulter.js100%100%100%100%
   browserslistTargetHandler.js100%100%100%100%
   cli.js98.88%100%100%98.88%114, 546, 578, 628
   defaults.js99.59%100%100%99.59%1629–1631, 1639, 286, 544
   defineConfig.js100%100%100%100%
   getClaimedAssetTypes.js100%100%100%100%
   normalization.js99.14%100%100%99.14%285–286, 356, 371
   target.js100%100%100%100%
   validateSchema.js94.67%100%100%94.67%100, 87, 89, 98
lib/container
   ContainerEntryDependency.js100%100%100%100%
   ContainerEntryModule.js100%100%100%100%
   ContainerEntryModuleFactory.js100%100%100%100%
   ContainerExposedDependency.js100%100%100%100%
   ContainerPlugin.js100%100%100%100%
   ContainerReferencePlugin.js100%100%100%100%
   FallbackDependency.js100%100%100%100%
   FallbackItemDependency.js100%100%100%100%
   FallbackModule.js100%100%100%100%
   FallbackModuleFactory.js100%100%100%100%
   HoistContainerReferencesPlugin.js100%100%100%100%
   ModuleFederationPlugin.js100%100%100%100%
   RemoteModule.js100%100%100%100%
   RemoteRuntimeModule.js100%100%100%100%
   RemoteToExternalDependency.js100%100%100%100%
   declaredRemotes.js100%100%100%100%
   moduleFederationHooks.js100%100%100%100%
   options.js100%100%100%100%
lib/context
   ContextExclusionPlugin.js100%100%100%100%
   ContextModule.js99.88%100%100%99.88%1495
   ContextModuleFactory.js95.70%100%100%95.70%230, 257, 276, 280–281, 289, 466, 487, 492, 534, 543, 545, 549, 552, 558–559
   ContextReplacementPlugin.js100%100%100%100%
lib/css
   CssGenerator.js99.29%100%100%99.29%1092, 134, 301, 849
   CssInjectStyleRuntimeModule.js100%100%100%100%
   CssLoadingRuntimeModule.js100%100%100%100%
   CssModule.js100%100%100%100%
   CssModulesPlugin.js98.72%100%100%98.72%217, 418, 432, 445, 458, 481, 494, 507, 520
   CssParser.js99.76%100%100%99.76%1094, 2431, 3078, 3081, 3087, 3520, 947
   CssServerStylesRuntimeModule.js100%100%100%100%
   conventions.js98.65%100%100%98.65%93
   cssMinify.js100%100%100%100%
   data.js99.84%100%100%99.84%229, 5601
   syntax-parser.js99.69%100%100%99.69%10776–10777, 11315–11316, 11353, 11563, 11612, 13930, 13991–13994, 14099–14100, 14198–14199, 14918, 15215, 15217, 15737, 16103, 18246, 2616, 3321, 3323, 3328, 3347, 4096, 4102
   syntax-printer.js99.33%100%100%99.33%2603–2604, 2606–2607, 2609–2610, 2615, 2885–2888, 2981, 353, 3666, 4091, 4227, 4927, 5238, 6026, 727
   syntax.js100%100%100%100%
   topologicalSort.js100%100%100%100%
lib/debug
   ProfilingPlugin.js94.70%100%100%94.70%419–421, 423, 427, 435, 439, 454, 582, 589, 598, 602, 611, 616, 622, 627
lib/define
   DefinePlugin.js99.42%100%100%99.42%1493, 936, 938, 943, 967
   DotenvPlugin.js97.58%100%100%97.58%276, 391, 439, 452–453
   EnvironmentPlugin.js97.14%100%100%97.14%49
lib/deno
   DenoTargetPlugin.js100%100%100%100%
lib/dependencies
   ConstDependency.js100%100%100%100%
   ContextElementDependency.js100%100%100%100%
   NullDependency.js100%100%100%100%
lib/dependencies/amd
   AMDDefineDependency.js100%100%100%100%
   AMDDefineDependencyParserPlugin.js100%100%100%100%
   AMDPlugin.js99.31%100%100%99.31%54
   AMDRequireArrayDependency.js100%100%100%100%
   AMDRequireContextDependency.js100%100%100%100%
   AMDRequireDependenciesBlock.js100%100%100%100%
   AMDRequireDependenciesBlockParserPlugin.js100%100%100%100%
   AMDRequireDependency.js100%100%100%100%
   AMDRequireItemDependency.js100%100%100%100%
   AMDRuntimeModules.js95.45%100%100%95.45%65
   LocalModule.js100%100%100%100%
   LocalModuleDependency.js100%100%100%100%
   

@github-actions

Copy link
Copy Markdown
Contributor

Generated code size

Comparing base (986efee) to head (4fa17b2). Merging this pull request will not change the code webpack generates.

What moved Tests Assets Gzip Raw Test edit
Changed, test untouched 0 0 — — —
Changed, test edited 0 0 — — —
New 0 0 — — —
Deleted 0 0 — — —
Unchanged — 8968 — — —

Read Changed, test untouched first: the test is byte-identical on both sides, so webpack generated the difference. Changed, test edited moved partly because the test did — Test edit is how many bytes the test gained, and a bundle that grew by less is not a regression. New and Deleted are whole files, not deltas — a new asset was created, not grown, so it reads gray (⚪ added) — and adding tests cannot bury a real change. Gzip decides, because that is what users download; raw is the tiebreak, and brotli and zstd are per asset below.

No asset changed size.

No runtime gained or lost a runtime module.

Built test/configCases with the defaults a user gets: 2249 test(s), 8968 asset(s), 100 emitted nothing.

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.45%. Comparing base (986efee) to head (4fa17b2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22744      +/-   ##
==========================================
+ Coverage   95.98%   96.45%   +0.47%     
==========================================
  Files         778      778              
  Lines      136313   136313              
  Branches    46009    46009              
==========================================
+ Hits       130837   131481     +644     
+ Misses       5476     4832     -644     
Flag Coverage Δ
css-parsing 24.76% <50.00%> (ø)
html5lib 26.56% <50.00%> (ø)
integration 81.24% <50.00%> (ø)
minify-corpora 90.44% <ø> (?)
syntax-equivalence 76.58% <ø> (ø)
test262 55.65% <50.00%> (?)
test262-parser 79.42% <ø> (ø)
unit 76.53% <100.00%> (+<0.01%) ⬆️
xmlconf 27.52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@codspeed

codspeed Bot commented Oct 17, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 43.61%

⚠️ 108 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 29 benchmarks have no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚠️ 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
❌ 2 regressed benchmarks
✅ 403 untouched benchmarks
⏩ 6 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory unit benchmark "html-printer-document-unit", beautify (deep nesting) 12.9 KB 148.7 KB -91.33%
❌ Memory benchmark "context-commonjs", scenario '{"name":"mode-development","mode":"development"}' 275.7 KB 371 KB -25.68%
⚡ Memory benchmark "wasm-modules-async", scenario '{"name":"mode-development","mode":"development"}' 967 KB 347.5 KB ×2.8

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/concatenation-cache-unaffected-guard (4fa17b2) with main (986efee)

Open in CodSpeed

Footnotes

  1. 6 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. ↩

@alexander-akait
alexander-akait merged commit 36f36bc into main Oct 17, 2026
70 checks passed
@alexander-akait
alexander-akait deleted the fix/concatenation-cache-unaffected-guard branch October 17, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: optimization Tree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant