Throw a warning for circular chunks#6225
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#fix/6189Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust. or load it into the REPL: |
There was a problem hiding this comment.
Pull request overview
This PR introduces a warning system for circular chunk dependencies that can occur during code splitting. The feature helps developers identify configuration issues with manual chunks that lead to circular dependencies between chunks, which can cause broken execution order.
Key changes:
- Adds circular chunk detection algorithm that traverses the chunk dependency graph using DFS
- Distinguishes between two scenarios: manual chunk conflicts (where all chunks in the cycle are manually configured) and issues caused by
onlyExplicitManualChunks(where static dependencies are bundled into entry chunks) - Provides context-specific warning messages to guide developers toward solutions
Reviewed changes
Copilot reviewed 35 out of 35 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Bundle.ts | Implements the checkCircularChunks method that detects cycles in the chunk dependency graph using depth-first search and emits appropriate warnings |
| src/Chunk.ts | Adds isManualChunk boolean flag to track whether a chunk was created from manual chunk configuration |
| src/utils/logs.ts | Adds the CIRCULAR_CHUNK warning code and logCircularChunk function that generates context-aware warning messages based on the type of circular dependency |
| test/chunking-form/samples/circular-manual-chunks/_config.js | Updates existing test to expect the new CIRCULAR_CHUNK warning |
| test/function/samples/circular-namespace-reexport-manual-chunks/_config.js | Updates existing test to expect the new CIRCULAR_CHUNK warning for manual chunk conflicts |
| test/chunking-form/samples/circular-chunks-warning-caused-by-only-explicit-manual-chunks/* | New test case demonstrating circular chunks caused by onlyExplicitManualChunks with test input files, configuration, and expected outputs for all module formats (amd, cjs, es, system) |
| test/chunking-form/samples/circular-chunks-warning-caused-by-manual-chunks-conflict/* | New test case demonstrating circular chunks caused by conflicting manual chunk configurations with test input files, configuration, and expected outputs for all module formats (amd, cjs, es, system) |
test/chunking-form/samples/circular-chunks-warning-caused-by-only-explicit-manual-chunks/c.js
Show resolved
Hide resolved
test/chunking-form/samples/circular-chunks-warning-caused-by-only-explicit-manual-chunks/b.js
Show resolved
Hide resolved
test/chunking-form/samples/circular-chunks-warning-caused-by-only-explicit-manual-chunks/a.js
Show resolved
Hide resolved
test/chunking-form/samples/circular-chunks-warning-caused-by-manual-chunks-conflict/c.js
Show resolved
Hide resolved
test/chunking-form/samples/circular-chunks-warning-caused-by-manual-chunks-conflict/b.js
Show resolved
Hide resolved
test/chunking-form/samples/circular-chunks-warning-caused-by-manual-chunks-conflict/a.js
Show resolved
Hide resolved
Performance report
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6225 +/- ##
=======================================
Coverage 98.81% 98.81%
=======================================
Files 272 272
Lines 10684 10717 +33
Branches 2862 2869 +7
=======================================
+ Hits 10557 10590 +33
Misses 85 85
Partials 42 42 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Related to #6189
Description
Code splitting is one of the most important features of a bundler. For example, manual bundling is often used for rarely changed third-party packages like
ReactorVue. However, most users do not know the dependency graph of these third-party packages, so themanualChunksoption may be configured incorrectly, as in this issue.In this PR, we introduce a warning for circular chunks, which may be caused by two scenarios. First, manual chunks conflict with each other. In this case, Rollup has no room for further improvement. Second, the issue is caused by
output.onlyExplicitManualChunks. In this case, we can do better in the future by bundling the static dependencies of manual chunks into a separate chunk, if bundling them into the entry module would cause circular chunks.