GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: inherit sideEffects past type-only nested package.json by xiaoxiaojx · Pull Request #21686 · webpack/webpack

Conversation

@xiaoxiaojx

@xiaoxiaojx xiaoxiaojx commented Aug 11, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

Nested type-only package.json files (e.g. {"type":"module"}) were shadowing a parent sideEffects flag, so unused modules from packages like entities stayed in the graph. Inherit the ancestor flag within compiler.context, rebase globs to the declaring package root, and stop at named packages / node_modules directory boundaries.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — test/configCases/side-effects/nested-package-json-sideEffects and nested-package-json-sideEffects-outside-context.

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

Yes — AI assisted implementation, tests, and PR drafting; changes were reviewed and verified locally.

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of inherited sideEffects settings in nested packages.
    • More accurately removes unused modules while retaining modules that may have side effects.
    • Preserved deferred-import re-export modules during optimization.
    • Improved behavior across package boundaries and configured build contexts.
    • Improved reliability when resolving package metadata from nested directories.
  • Chores

    • Added a patch release entry documenting the updated side-effects behavior.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@changeset-bot

changeset-bot Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9bc99bc

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) area: optimization Tree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids) labels Aug 11, 2026
@xiaoxiaojx
xiaoxiaojx marked this pull request as draft August 11, 2026 17:25
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "tools"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f02df7db-3228-4733-85fd-69e97ac6b91e

📥 Commits

Reviewing files that changed from the base of the PR and between bf21f16 and 9bc99bc.

⛔ Files ignored due to path filters (35)
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/node_modules/outside-context-sef/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/node_modules/outside-context-sef/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/node_modules/outside-context-sef/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/node_modules/outside-context-sef/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/node_modules/outside-context-sef/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/declared-nested-sef/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/declared-nested-sef/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/declared-nested-sef/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/declared-nested-sef/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/declared-nested-sef/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/explicit-nested-true/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/explicit-nested-true/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/explicit-nested-true/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/explicit-nested-true/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/explicit-nested-true/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-array-sef/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-array-sef/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-array-sef/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-array-sef/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-array-sef/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-string-sef/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-string-sef/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-string-sef/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-string-sef/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/glob-string-sef/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/shadowed-sef/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/shadowed-sef/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/shadowed-sef/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/shadowed-sef/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/shadowed-sef/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/stop-at-node-modules/esm/heavy.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/stop-at-node-modules/esm/index.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/stop-at-node-modules/esm/light.js is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/stop-at-node-modules/esm/package.json is excluded by !**/node_modules/**
  • test/configCases/side-effects/nested-package-json-sideEffects/node_modules/stop-at-node-modules/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (18)
  • .changeset/047-inherit-nested-sideEffects.md
  • lib/dependencies/ImportMetaGlobHelpers.js
  • lib/optimize/SideEffectsFlagPlugin.js
  • lib/util/identifier.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/heavy.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/light.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/webpack.config.js
  • test/configCases/side-effects/nested-package-json-sideEffects/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/heavy.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/light.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects/webpack.config.js
🚧 Files skipped from review as they are similar to previous changes (18)
  • test/configCases/side-effects/nested-package-json-sideEffects/webpack.config.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/package.json
  • .changeset/047-inherit-nested-sideEffects.md
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/light.js
  • test/configCases/side-effects/nested-package-json-sideEffects/package.json
  • lib/util/identifier.js
  • lib/dependencies/ImportMetaGlobHelpers.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/package.json
  • test/configCases/side-effects/nested-package-json-sideEffects/local-app-nested/esm/heavy.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/webpack.config.js
  • test/configCases/side-effects/nested-package-json-sideEffects/index.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/light.js
  • test/configCases/side-effects/nested-package-json-sideEffects-outside-context/src/climb-nested/esm/heavy.js
  • lib/optimize/SideEffectsFlagPlugin.js

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Changes

SideEffectsFlagPlugin now inherits sideEffects metadata from ancestor package.json files within the compiler context. It caches resolved metadata per module creation and applies it during module creation. New configuration cases cover nested packages and context boundaries.

Suggested reviewers: hai-x

Side-effects metadata inheritance

Layer / File(s) Summary
Package metadata resolution
lib/optimize/SideEffectsFlagPlugin.js, lib/util/identifier.js, lib/dependencies/ImportMetaGlobHelpers.js
The plugin resolves inherited sideEffects values while traversing ancestor package metadata. Shared request normalization is exported and reused.
Module creation integration
lib/optimize/SideEffectsFlagPlugin.js
afterResolve caches resolved metadata, and module creation applies the cached value.
Nested package regression coverage
test/configCases/side-effects/nested-package-json-sideEffects/*, test/configCases/side-effects/nested-package-json-sideEffects-outside-context/*, .changeset/047-inherit-nested-sideEffects.md
Configuration cases verify nested declarations, glob rebasing, local package metadata, node_modules boundaries, and paths outside the compiler context. The changeset records the patch release.

Merge Risk: ⚪ Minimal · up to 9bc99

This change adjusts inheritance of package side-effect metadata and adds focused regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the valid fix: type and accurately describes inherited sideEffects behavior for nested package.json files.
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.

Warning

Your free Security trial is over. An organization admin can activate billing to continue.


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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (7b7f6dd).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@7b7f6dd
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@7b7f6dd
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@7b7f6dd
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xiaoxiaojx
xiaoxiaojx requested a review from hai-x August 11, 2026 17:27
@codecov

codecov Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.58333% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.85%. Comparing base (bc3e930) to head (9bc99bc).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
lib/optimize/SideEffectsFlagPlugin.js 89.36% 10 Missing ⚠️

❌ Your patch check has failed because the patch coverage (89.58%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #21686    +/-   ##
========================================
  Coverage   94.84%   94.85%            
========================================
  Files         677      683     +6     
  Lines       87465    87788   +323     
  Branches    26258    26334    +76     
========================================
+ Hits        82956    83270   +314     
- Misses       4509     4518     +9     
Flag Coverage Δ
css-parsing 26.26% <26.04%> (+<0.01%) ⬆️
html5lib 30.49% <26.04%> (-0.01%) ⬇️
integration 87.95% <89.58%> (+0.03%) ⬆️
syntax-equivalence 79.68% <100.00%> (+<0.01%) ⬆️
test262 51.40% <38.54%> (-0.03%) ⬇️
unit 55.58% <38.54%> (-0.03%) ⬇️

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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Generated code size

Comparing 9bc99bc merged into bf21f16 against bf21f16. Merging this pull request adds 2 new asset(s).

Changed New Deleted Unchanged Gzip change Raw change Gzip new/gone Raw new/gone
Cases 0 2 0 1813 — — +3.36 KiB +12.74 KiB
Assets 0 2 0 6829 — — +3.36 KiB +12.74 KiB
Runtimes 0 2 0 2131 — — — —

Gzip change decides — it is what a user downloads, and a re-encoding can cut raw bytes while costing wire bytes. Raw change is the tiebreak: it is what the generator wrote, so it is what has to be decompressed and parsed. Both are over assets both runs emit; bytes an added or deleted case brings with it are counted apart, under new/gone. Brotli and zstd are per asset in the table below.

No asset that both runs emit changed size — everything below is new or deleted.

2 asset(s) this pull request adds
Asset Raw Gzip (9) Brotli (11) Zstd (19)
➕ side-effects/nested-package-json-sideEffects bundle0.js 8.03 KiB 1.89 KiB 1.63 KiB 1.85 KiB
➕ side-effects/nested-package-json-sideEffects-outside-context bundle0.js 4.71 KiB 1.47 KiB 1.29 KiB 1.47 KiB

No runtime that both runs build changed which runtime modules it carries.

2 runtime(s) this pull request adds or no longer builds
Runtime Modules
➕ side-effects/nested-package-json-sideEffects main 2
➕ side-effects/nested-package-json-sideEffects-outside-context main 2

Built test/configCases with the defaults a user gets: 1815 case(s), 6831 asset(s), 49 emitted nothing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xiaoxiaojx
xiaoxiaojx force-pushed the fix/nested-package-json-sideEffects branch from 475a3e0 to 4ba77ec Compare August 11, 2026 17:38
@codspeed

codspeed Bot commented Aug 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ 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

⚡ 4 improved benchmarks
❌ 2 regressed benchmarks
✅ 322 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 474 KB 952 KB -50.21%
❌ Memory benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 658 KB 844.6 KB -22.09%
⚡ Memory benchmark "many-modules-esm", scenario '{"name":"mode-development","mode":"development"}' 2,301 KB 910.8 KB ×2.5
⚡ Memory benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 302.6 KB 212.8 KB +42.23%
⚡ Memory benchmark "devtool-eval", scenario '{"name":"mode-production","mode":"production"}' 14.8 MB 11.4 MB +29.51%
⚡ Memory unit benchmark "html-printer-document-unit", walk (fragment, tr context) 25.2 KB 19.7 KB +27.47%

Tip

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


Comparing fix/nested-package-json-sideEffects (9bc99bc) with main (13c2f94)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (bf21f16) during the generation of this report, so 13c2f94 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xiaoxiaojx
xiaoxiaojx marked this pull request as ready for review August 11, 2026 17:59
coderabbitai[bot]
coderabbitai Bot reviewed Aug 11, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
lib/optimize/SideEffectsFlagPlugin.js (2)

278-286: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Read compiler.inputFileSystem inside the hook, not at apply time.

compiler.inputFileSystem is reassigned during the compiler lifecycle, for example by NodeEnvironmentPlugin on watch invalidation and on close. The captured reference can become stale, and the !inputFileSystem guard then silently disables the whole resolution path for the rest of the run.

♻️ Proposed change
-		const inputFileSystem = compiler.inputFileSystem;
 		compiler.hooks.compilation.tap(
 			PLUGIN_NAME,
 			(compilation, { normalModuleFactory }) => {
 				const moduleGraph = compilation.moduleGraph;
 				normalModuleFactory.hooks.afterResolve.tapAsync(
 					PLUGIN_NAME,
 					(resolveData, callback) => {
+						const inputFileSystem = compiler.inputFileSystem;
 						if (!inputFileSystem) return callback();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/optimize/SideEffectsFlagPlugin.js` around lines 278 - 286, Update the
compilation hook around `normalModuleFactory.hooks.afterResolve` to read
`compiler.inputFileSystem` when the `afterResolve` callback executes, rather
than capturing it before `compiler.hooks.compilation.tap`. Apply the existing
missing-filesystem guard to this freshly read value so resolution continues
using the current compiler filesystem after lifecycle reassignment.

170-226: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Memoize the ancestor walk per directory.

afterResolve runs for every resolved module. Every module inside a node_modules package that declares no sideEffects repeats the full ancestor walk, including one readJson per ancestor directory. The result depends only on descriptionFileRoot, not on relativePath, so the walk can be cached per directory and reused.

Store the resolved owning package root plus its sideEffects value in a Map keyed by descriptionFileRoot (scoped to compiler.root, like globToRegexpCache), then compute relativePath per module from that cached root. This also removes repeated work when the input filesystem is not a caching one.

As per coding guidelines: "Evaluate time and memory costs of changes, especially on hot paths."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/optimize/SideEffectsFlagPlugin.js` around lines 170 - 226, Memoize the
ancestor walk in the afterResolve path using a Map scoped to compiler.root,
keyed by descriptionFileRoot, alongside globToRegexpCache. Cache both the owning
package root and its sideEffects value, including no-result cases, then compute
each module’s relativePath from the cached root instead of repeating readJson
traversal. Preserve existing boundary and error behavior while avoiding
unbounded per-module cache growth.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/optimize/SideEffectsFlagPlugin.js`:
- Around line 197-208: Update the ancestor package.json error handling in the
readJson callback to continue walking via next() for missing or unreadable paths
(ENOENT, ENOTDIR, EISDIR, ENAMETOOLONG) and JSON parse SyntaxError, while
preserving callback(err) for other I/O failures. Keep the existing
parent-directory traversal behavior unchanged.

---

Nitpick comments:
In `@lib/optimize/SideEffectsFlagPlugin.js`:
- Around line 278-286: Update the compilation hook around
`normalModuleFactory.hooks.afterResolve` to read `compiler.inputFileSystem` when
the `afterResolve` callback executes, rather than capturing it before
`compiler.hooks.compilation.tap`. Apply the existing missing-filesystem guard to
this freshly read value so resolution continues using the current compiler
filesystem after lifecycle reassignment.
- Around line 170-226: Memoize the ancestor walk in the afterResolve path using
a Map scoped to compiler.root, keyed by descriptionFileRoot, alongside
globToRegexpCache. Cache both the owning package root and its sideEffects value,
including no-result cases, then compute each module’s relativePath from the
cached root instead of repeating readJson traversal. Preserve existing boundary
and error behavior while avoiding unbounded per-module cache growth.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f1d2eb66-2173-428c-83f0-e3ca40f61717

📥 Commits

Reviewing files that changed from the base of the PR and between 475a3e0 and 4ba77ec.

📒 Files selected for processing (3)
  • .changeset/047-inherit-nested-sideEffects.md
  • lib/optimize/SideEffectsFlagPlugin.js
  • test/configCases/side-effects/nested-package-json-sideEffects/index.js
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • webpack/schema-utils (auto-detected)
  • webpack/tapable (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/047-inherit-nested-sideEffects.md
  • test/configCases/side-effects/nested-package-json-sideEffects/index.js

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/optimize/SideEffectsFlagPlugin.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

alexander-akait
alexander-akait reviewed Aug 11, 2026
View reviewed changes

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

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.

That is interesting, initially we don’t inherit this specially, yes this idea was too, but as I remember we declined it in testing, let’s take a look how other bundlers do it

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xiaoxiaojx reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@xiaoxiaojx

xiaoxiaojx commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

@alexander-akait Thanks. I checked other bundlers: Rspack/esbuild/Parcel/Rolldown all use the nearest enclosing package.json only (Rolldown explicitly declined walking up for a sideEffects field — rolldown#3336). I noticed this gap while reviewing production bundle output with AI: root sideEffects: false often gets shadowed by a nested type-only package.json under node_modules, which looks like either a packaging omission or an expectation that bundlers would inherit. This PR treats that as a reasonable optimization (scoped to node_modules, with context / named-package stops so app-local nests still shadow). If there was a clearer historical reason not to support this, we’re happy to reconsider.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hai-x

hai-x commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Measured the win, across majors:

import { decodeXML } from "entities" with mode: "production" + minimize: false

version layout before after ratio note
4.5.0 lib/esm/package.json stub 107,803 70,082 −35%
6.0.1 dist/esm + dist/commonjs stubs 33,649 22,498 −33%
8.0.0 ESM-only, no nested manifest 25,907 25,907 no change It ships ESM-only, no dist/esm dirs
xiaoxiaojx and alexander-akait reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xiaoxiaojx
xiaoxiaojx force-pushed the fix/nested-package-json-sideEffects branch from 4ba77ec to 2f57498 Compare August 19, 2026 13:11
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xiaoxiaojx
fix: inherit sideEffects past type-only nested package.json
9bc99bc
@xiaoxiaojx
xiaoxiaojx force-pushed the fix/nested-package-json-sideEffects branch from 2f57498 to 9bc99bc Compare August 23, 2026 07:37
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Types Coverage

Coverage after merging fix/nested-package-json-sideEffects into main will be
99.27%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
bin
   webpack.js98.82%100%100%98.82%103
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/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
   APIPlugin.js100%100%100%100%
   AsyncDependenciesBlock.js100%100%100%100%
   AutomaticPrefetchPlugin.js100%100%100%100%
   BannerPlugin.js100%100%100%100%
   Cache.js98.21%100%100%98.21%101
   CacheFacade.js100%100%100%100%
   Chunk.js99.72%100%100%99.72%42
   ChunkGraph.js100%100%100%100%
   ChunkGroup.js100%100%100%100%
   ChunkTemplate.js100%100%100%100%
   CircularModulesPlugin.js99.35%100%100%99.35%244
   CleanPlugin.js99.12%100%100%99.12%212, 232
   CodeGenerationResults.js100%100%100%100%
   CompatibilityPlugin.js100%100%100%100%
   Compilation.js98.49%100%100%98.49%1683, 2002, 2009, 2017, 2039, 2042, 2981, 3460–3461, 3493, 4202, 4232, 4285–4286, 4290, 4295, 4311–4312, 4326–4327, 4332–4333, 4855, 4881, 5691, 5723, 5740, 5758, 5774, 5789, 5814–5815, 5817, 6152, 6157, 6163, 6166, 6173, 6185, 6187, 6191, 6209, 6224, 6258, 6314, 6338, 6454, 807–808
   Compiler.js99.56%100%100%99.56%1174–1175, 1183
   ConcatenationScope.js99.12%100%100%99.12%303
   ConditionalInitFragment.js100%100%100%100%
   ConstPlugin.js100%100%100%100%
   ContextExclusionPlugin.js100%100%100%100%
   ContextModule.js99.88%100%100%99.88%1554
   ContextModuleFactory.js97.29%100%100%97.29%289, 465, 486, 491, 532, 543, 545, 549, 558–559
   ContextReplacementPlugin.js100%100%100%100%
   DefinePlugin.js99.12%100%100%99.12%1109, 182–183, 199, 218, 292
   DependenciesBlock.js100%100%100%100%
   Dependency.js98.54%100%100%98.54%498, 545
   DependencyTemplate.js100%100%100%100%
   DependencyTemplates.js100%100%100%100%
   DotenvPlugin.js98.41%100%100%98.41%415, 428–429
   DynamicEntryPlugin.js100%100%100%100%
   EntryOptionPlugin.js100%100%100%100%
   EntryPlugin.js100%100%100%100%
   Entrypoint.js100%100%100%100%
   EnvironmentPlugin.js97.14%100%100%97.14%49
   ErrorHelpers.js100%100%100%100%
   EvalDevToolModulePlugin.js100%100%100%100%
   EvalSourceMapDevToolPlugin.js100%100%100%100%
   ExportsInfo.js100%100%100%100%
   ExportsInfoApiPlugin.js100%100%100%100%
   ExternalModule.js98.71%100%100%98.71%1270, 1273, 534–538, 540, 686
   ExternalModuleFactoryPlugin.js100%100%100%100%
   ExternalsPlugin.js100%100%100%100%
   FileSystemInfo.js99.53%100%100%99.53%187, 2455–2456, 2459, 2470, 2481, 2492, 285, 3929, 3944, 3968
   FlagAllModulesAsUsedPlugin.js100%100%100%100%
   FlagDependencyExportsPlugin.js98.36%100%100%98.36%505, 514, 517, 521, 533
   FlagDependencyUsagePlugin.js100%100%100%100%
   FlagEntryExportAsUsedPlugin.js100%100%100%100%
   Generator.js100%100%100%100%
   HotModuleReplacementPlugin.js100%100%100%100%
   HotUpdateChunk.js100%100%100%100%
   IgnorePlugin.js100%100%100%100%
   IgnoreWarningsPlugin.js100%100%100%100%
   InitFragment.js100%100%100%100%
   JavascriptMetaInfoPlugin.js100%100%100%100%
   LazyBarrel.js100%100%100%100%
   LibraryTemplatePlugin.js100%100%100%100%
   LoaderOptionsPlugin.js100%100%100%100%
   LoaderTargetPlugin.js100%100%100%100%
   MainTemplate.js100%100%100%100%
   ManifestPlugin.js100%100%100%100%
   Module.js98.51%100%100%98.51%1314, 1319, 1379, 1393, 1455, 1464
   ModuleFactory.js100%100%100%100%
   ModuleFilenameHelpers.js98.90%100%100%98.90%111, 113
   ModuleGraph.js99.78%100%100%99.78%1180
   ModuleGraphConnection.js100%100%100%100%
   ModuleInfoHeaderPlugin.js100%100%100%100%
   ModuleNotFoundError.js100%100%100%100%
   ModuleProfile.js100%100%100%100%
   ModuleSourceTypeConstants.js100%100%100%100%
   ModuleTemplate.js100%100%100%100%
   ModuleTypeConstants.js100%100%100%100%
   MultiCompiler.js99.72%100%100%99.72%729
   MultiStats.js100%100%100%100%
   MultiWatching.js100%100%100%100%
   NoEmitOnErrorsPlugin.js100%100%100%100%
   NodeStuffPlugin.js100%100%100%100%
   NormalModule.js97.99%100%100%97.99%1045, 1048, 1065, 1082, 1330, 1364, 1380, 1835, 2132, 2137–2147, 29
   NormalModuleFactory.js99.01%100%100%99.01%1341, 1790, 1801, 1811, 1862–1864, 1871, 732, 744
   NormalModuleReplacementPlugin.js100%100%100%100%
   NullFactory.js100%100%100%100%
   OptimizationStages.js100%100%100%100%
   OptionsApply.js100%100%100%100%
   Parser.js100%100%100%100%
   PlatformPlugin.js100%100%100%100%
   PrefetchPlugin.js100%100%100%100%
   ProgressPlugin.js99.80%100%100%99.80%694
   ProvidePlugin.js100%100%100%100%
   RawModule.js100%100%100%100%
   RecordIdsPlugin.js100%100%100%100%
   RequestShortener.js100%100%100%100%
   ResolverFactory.js100%100%100%100%
   RuntimeGlobals.js100%100%100%100%
   RuntimeModule.js100%100%100%100%
   RuntimePlugin.js95.71%100%100%95.71%312, 368, 377, 380, 404, 422, 443–444, 467, 487–488, 524–525, 548, 561–562, 634, 647, 668, 687
   RuntimeTemplate.js99.87%100%100%99.87%251, 3086
   SelfModuleFactory.js100%100%100%100%
   SingleEntryPlugin.js100%100%100%100%
   SourceMapDevToolModuleOptionsPlugin.js100%100%100%100%
   SourceMapDevToolPlugin.js98.63%100%100%98.63%229, 233, 235, 429, 440, 899
   Stats.js100%100%100%100%
   Template.js100%100%100%100%
   TemplatedPathPlugin.js99.48%100%100%99.48%366–367
   UseStrictPlugin.js100%100%100%100%
   WarnCaseSensitiveModulesPlugin.js100%100%100%100%
   WarnDeprecatedOptionPlugin.js100%100%100%100%
   WarnNoModeSetPlugin.js100%100%100%100%
   WatchIgnorePlugin.js100%100%100%100%
   Watching.js100%100%100%100%
   WebpackError.js100%100%100%100%
   WebpackIsIncludedPlugin.js100%100%100%100%
   WebpackOptionsApply.js100%100%100%100%
   WebpackOptionsDefaulter.js100%100%100%100%
   buildChunkGraph.js99.87%100%100%99.87%375
   cli.js98.63%100%100%98.63%10, 117, 547, 579, 629, 903
   index.js99.73%100%100%99.73%184
   validateSchema.js94.67%100%100%94.67%100, 87, 89, 98
   webpack.js97.12%100%100%97.12%10, 274, 296, 298
lib/asset
   AssetBytesGenerator.js100%100%100%100%
   AssetBytesParser.js100%100%100%100%
   AssetGenerator.js100%100%100%100%
   AssetModule.js100%100%100%100%
   AssetModulesPlugin.js98.15%100%100%98.15%338, 362, 365, 495, 57, 62
   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%
   IdleFileCachePlugin.js97.92%100%100%97.92%75, 87, 95
   MemoryCachePlugin.js92%100%100%92%33, 42
   MemoryWithGcCachePlugin.js93.42%100%100%93.42%107, 121–122, 131, 89
   PackFileCacheStrategy.js96.52%100%100%96.52%1317, 1417, 1421, 1483, 1719, 1803, 1826, 1858, 682, 701, 711–713, 715, 731–732, 737, 740, 742, 747, 752, 777, 783, 817, 823,
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alexander-akait
alexander-akait approved these changes Aug 25, 2026
View reviewed changes
@alexander-akait
alexander-akait merged commit 7b7f6dd into main Aug 25, 2026
67 of 68 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the fix/nested-package-json-sideEffects branch August 25, 2026 08:11
@github-actions github-actions Bot mentioned this pull request Aug 25, 2026
chore(release): new release #21545
Merged
alexander-akait added a commit that referenced this pull request Aug 25, 2026
@alexander-akait
fix(side-effects): read the inherited flag from the resolved file
3b0bc44
Follow-up to #21686. The flag was read from the description-file root, so a
symlinked workspace package inherited for the request coming through
node_modules but not for the relative imports its own files make. Report the
ancestor package.json files the walk consults as dependencies of the resolve,
and let an unreadable one decline the inheritance rather than fail the module.
@alexander-akait alexander-akait mentioned this pull request Aug 25, 2026
fix(side-effects): read the inherited flag from the resolved file #21826
Merged
alexander-akait added a commit that referenced this pull request Aug 25, 2026
@alexander-akait
fix(side-effects): read the inherited flag from the resolved file (#2…
f4ddefb
…1826)

* fix(side-effects): read the inherited flag from the resolved file

Follow-up to #21686. The flag was read from the description-file root, so a
symlinked workspace package inherited for the request coming through
node_modules but not for the relative imports its own files make. Report the
ancestor package.json files the walk consults as dependencies of the resolve,
and let an unreadable one decline the inheritance rather than fail the module.

* fix(side-effects): stop inheriting past an unreadable ancestor manifest

A manifest that is there but cannot be read declares something unknown, so
letting an outer sideEffects: false speak for it can drop code that runs. Only
an absent one keeps the walk going. Also makes the symlink probe idempotent, so
a probe left behind by a failed cleanup no longer skips the case for good.

* test(side-effects): fail the symlink filter on anything but a missing privilege

* fix(test): keep the symlink filter on the Node 10 baseline

* test(side-effects): shorten the symlink helper annotation
@JSerFeng JSerFeng mentioned this pull request Aug 26, 2026
fix: inherit sideEffects through nested package metadata web-infra-dev/rspack#15336
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments
@alexander-akait alexander-akait alexander-akait approved these changes
@hai-x hai-x Awaiting requested review from hai-x

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area: optimization Tree-shaking, splitChunks, concatenation, ids (lib/optimize, lib/ids) area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@xiaoxiaojx @hai-x @alexander-akait
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.