Skip to content

Sort manual chunks by module execution order#6240

Merged
lukastaegert merged 3 commits intomasterfrom
fix/6233
Jan 19, 2026
Merged

Sort manual chunks by module execution order#6240
lukastaegert merged 3 commits intomasterfrom
fix/6233

Conversation

@TrickyPi
Copy link
Member

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:
resolves #6233

Description

This PR sorts manual chunks before the chunk-generation pass, allowing Rollup to bundle shared dependencies into the earlier manual chunk in the execution order, which helps avoid circular chunk cycles in certain scenarios.

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

vercel bot commented Jan 17, 2026

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

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

Request Review

@TrickyPi TrickyPi changed the title Fix/6233 Sort manual chunks by module execution order Jan 17, 2026
@github-actions
Copy link

github-actions bot commented Jan 17, 2026

Thank you for your contribution! ❤️

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

npm install rollup/rollup#fix/6233

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-iq167nwor-rollup-js.vercel.app/repl/?pr=6240

@github-actions
Copy link

github-actions bot commented Jan 17, 2026

Performance report

  • BUILD: 7007ms, 838 MB
    • initialize: 0ms, 24.6 MB (+7%)
    • generate module graph: 2614ms, 637 MB
      • generate ast: 1369ms, 627 MB
    • sort and bind modules: 405ms, 699 MB
    • mark included statements: 3976ms, 838 MB
      • treeshaking pass 1: 2324ms, 849 MB (+2%)
      • treeshaking pass 2: 468ms, 813 MB
      • treeshaking pass 3: 399ms, 836 MB
      • treeshaking pass 4: 387ms, 817 MB
      • treeshaking pass 5: 386ms, 838 MB
  • GENERATE: 696ms, 914 MB
    • initialize render: 0ms, 839 MB
    • generate chunks: 50ms, 819 MB
      • optimize chunks: 0ms, 827 MB
    • render chunks: 629ms, 888 MB
    • transform chunks: 17ms, 914 MB
    • generate bundle: 0ms, 914 MB

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 fixes issue #6233 by sorting manual chunks by execution order (execIndex) rather than alphabetically by alias name. This ensures that shared dependencies are bundled into the chunk that executes first, helping to avoid circular chunk dependencies.

Changes:

  • Modified chunk assignment logic to sort manual chunks by module execution order instead of alphabetically
  • Simplified the manual chunk assignment flow in Bundle.ts by removing intermediate sorting step
  • Added comprehensive test coverage for the new sorting behavior

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Bundle.ts Removed alphabetical sorting of manual chunks and simplified logic by directly populating the map instead of using an intermediate array
src/utils/chunkAssignment.ts Added sorting by execIndex (execution order) when processing manual chunks to ensure shared dependencies go into earlier chunks
test/function/samples/manual-chunks-order/*.js New test case validating that manual chunks are sorted by entry execution index
test/function/samples/circular-namespace-reexport-manual-chunks/_config.js Updated expected circular chunk warning to reflect new execution-order-based sorting (formatters.js now sorted before types.js)
test/chunking-form/samples/manual-chunks-function/_expected//.js Updated expected output across multiple formats (amd, cjs, es, system) to reflect that dep2 is now bundled into chunk-c (executed first) instead of chunk-b

@codecov
Copy link

codecov bot commented Jan 17, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6240      +/-   ##
==========================================
- Coverage   98.81%   98.81%   -0.01%     
==========================================
  Files         272      272              
  Lines       10720    10717       -3     
  Branches     2870     2869       -1     
==========================================
- Hits        10593    10590       -3     
  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.

Thanks, looks good!

@lukastaegert lukastaegert added this pull request to the merge queue Jan 19, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 19, 2026
@lukastaegert lukastaegert added this pull request to the merge queue Jan 19, 2026
Merged via the queue into master with commit cde042f Jan 19, 2026
48 checks passed
@lukastaegert lukastaegert deleted the fix/6233 branch January 19, 2026 09:37
@github-actions
Copy link

This PR has been released as part of rollup@4.55.2. You can test it via npm install rollup.

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.

[BUG] manualChunks alias name causes circle dependency issue

3 participants