Skip to content

Throw a warning for circular chunks#6225

Merged
lukastaegert merged 1 commit intomasterfrom
fix/6189
Jan 4, 2026
Merged

Throw a warning for circular chunks#6225
lukastaegert merged 1 commit intomasterfrom
fix/6189

Conversation

@TrickyPi
Copy link
Member

@TrickyPi TrickyPi commented Jan 1, 2026

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

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 React or Vue. However, most users do not know the dependency graph of these third-party packages, so the manualChunks option 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.

Copilot AI review requested due to automatic review settings January 1, 2026 15:01
@vercel
Copy link

vercel bot commented Jan 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
rollup Ready Ready Preview, Comment Jan 1, 2026 3:01pm

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#fix/6189

Notice: 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:
https://rollup-96267f7yb-rollup-js.vercel.app/repl/?pr=6225

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

Performance report

  • BUILD: 7008ms, 846 MB
    • initialize: 0ms, 24.2 MB
    • generate module graph: 2607ms, 631 MB
      • generate ast: 1367ms (-54ms, -3.8%), 622 MB
    • sort and bind modules: 404ms, 688 MB
    • mark included statements: 3978ms, 846 MB
      • treeshaking pass 1: 2348ms, 834 MB
      • treeshaking pass 2: 463ms, 817 MB
      • treeshaking pass 3: 398ms, 844 MB
      • treeshaking pass 4: 384ms, 819 MB
      • treeshaking pass 5: 382ms, 846 MB
  • GENERATE: 686ms (-20ms, -2.9%), 906 MB
    • initialize render: 0ms, 846 MB
    • generate chunks: 49ms, 821 MB
      • optimize chunks: 0ms, 813 MB (-4%)
    • render chunks: 625ms, 879 MB
    • transform chunks: 16ms, 906 MB
    • generate bundle: 0ms, 906 MB

@codecov
Copy link

codecov bot commented Jan 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (fe42b2d) to head (f01c619).
⚠️ Report is 6 commits behind head on master.

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.
📢 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.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@lukastaegert lukastaegert enabled auto-merge January 4, 2026 06:54
@lukastaegert lukastaegert added this pull request to the merge queue Jan 4, 2026
Merged via the queue into master with commit e0bfc4b Jan 4, 2026
51 checks passed
@lukastaegert lukastaegert deleted the fix/6189 branch January 4, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants