Latest Results
fix: reduce false positives in chunk optimizer circular dependency detection (#9049)
## Summary
PR #8371 improved circular dependency detection in the chunk optimizer
to fix #8361 (`__commonJSMin is not a function`). However, the fix
introduced an over-approximation that blocks many legitimate chunk
merges, causing a significant regression in bundle size and file count.
Fixes #9093
## Problem
The current algorithm in `would_create_circular_dependency` does a BFS
from `source.deps āŖ target.deps` and simulates post-merge edges for
**every** chunk that depends on source. This causes false positives
because:
1. Starting BFS from `target.deps` means target can trivially "reach
itself" through any transitive dependency that also depends on source
2. The post-merge edge simulation amplifies this by redirecting any
source-dependent chunk back to target
In a large application with ~2,200 entry points, this blocks **1,046
legitimate merges**, producing **+1,224 extra chunks** and **+8% bundle
size**.
## Fix
Split the algorithm into two cases based on whether source has
dependencies:
- **Source has deps**: Only BFS from `source.deps` without post-merge
simulation. This is sufficient because if target is reachable from
source's dependency tree, merging would create a real cycle.
- **Source has no deps** (e.g., runtime chunk): Keep the full algorithm
with `target.deps` BFS and post-merge simulation. This correctly detects
cycles like `target ā chunk_A ā source(=target after merge)`, which is
the pattern from #8361.
## Results
Tested on a large application (~2,200 entry points):
| Metric | Before (rc.9) | After (this fix) | Improvement |
|--------|--------------|-------------------|-------------|
| JS files | 3,212 | 2,418 | **-794 (-25%)** |
| JS size | 73.13 MB | 63.99 MB | **-9.14 MB (-12.5%)** |
## Testing
- ā
`#8361` and `#8361_2` integration tests pass (the bug this algorithm
was designed to fix)
- ā
Full integration test suite: **1,652 passed**, 0 failed (1 skipped
due to missing test262 submodule)
- ā
New regression test added (`#9049`)
- ā
Verified on large production application
Fixes vitejs/vite#22007
---------
Co-authored-by: Alon Mizrahi <almizrahi@paloaltonetworks.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: IWANABETHATGUY <iwanabethatguy@qq.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Latest Branches
+1%
-1%
TheAlexLichter:fix/copy-module-tolerate-missing 0%
04-10-fix_rolldown_plugin_vite_manifest_handle_duplicate_chunk_names_for_css_entries Ā© 2026 CodSpeed Technology