Repository navigation
feat: inline common chunks containing import() and deduplicate shared code in lazy chunks - #11034
Conversation
✅ Deploy Preview for rolldown-rs canceled.
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Dead dynamic imports can incorrectly propagate metadata and hash dependencies into carrier chunks.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Extends inline common chunks to support internal dynamic imports, deduplicate factories across lazy loading paths, and allow unlimited size thresholds.
Changes:
- Tracks dynamic-import and
import.metabehavior per retained statement. - Adds entry-path-aware factory placement and dynamic-edge projection.
- Adds comprehensive fixtures, behavioral tests, and documentation.
| File | Description |
|---|---|
packages/rolldown/tests/src/inline-common-chunks/harness.ts |
Updates roots and registration checks. |
packages/rolldown/tests/behaviors/inline-common-chunks/inline-common-chunks.test.ts |
Adds dynamic-loading and placement tests. |
packages/rolldown/src/options/output-options.ts |
Documents unlimited sizing. |
internal-docs/inline-common-chunks/implementation.md |
Documents implementation changes. |
internal-docs/inline-common-chunks/design.md |
Documents loading-path placement. |
internal-docs/code-splitting/implementation.md |
Documents earlier placement preservation. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/kept_as_file/dynamic_import_member/artifacts.snap |
Removes obsolete snapshot. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/errors/max_size_negative/artifacts.snap |
Updates validation message. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/shared.js |
Adds shared dynamic loader fixture. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/lazy.js |
Adds lazy target fixture. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/b.js |
Adds second fixture entry. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/artifacts.snap |
Captures inlined loader output. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/a.js |
Adds loader-consuming entry. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/_test.mjs |
Verifies runtime behavior. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_import_member/_config.json |
Configures fixture inputs. |
crates/rolldown/tests/rolldown/function/inline_common_chunks/dynamic_entry_reader/artifacts.snap |
Reflects inherited factory removal. |
crates/rolldown/src/utils/prepare_build_context.rs |
Accepts positive infinity. |
crates/rolldown/src/stages/link_stage/reference_needed_symbols.rs |
Preserves conditional helper demand. |
crates/rolldown/src/stages/generate_stage/inline_common_chunks/select.rs |
Expands candidate selection rules. |
crates/rolldown/src/stages/generate_stage/inline_common_chunks/rewire.rs |
Projects copied dynamic edges. |
crates/rolldown/src/stages/generate_stage/inline_common_chunks/place.rs |
Adds entry-path-aware pruning. |
crates/rolldown/src/stages/generate_stage/dynamic_already_loaded.rs |
Preserves inline candidates. |
crates/rolldown/src/stages/generate_stage/chunk_optimizer.rs |
Avoids premature candidate merging. |
crates/rolldown/src/ast_scanner/impl_visit.rs |
Records per-statement metadata. |
crates/rolldown_testing/_config.schema.json |
Documents infinity semantics. |
crates/rolldown_error/src/build_diagnostic/events/invalid_option.rs |
Updates validation diagnostics. |
crates/rolldown_common/src/types/stmt_info.rs |
Adds statement-level ImportMeta. |
crates/rolldown_common/src/inner_bundler_options/types/inline_common_chunks_options.rs |
Documents normalized unlimited size. |
crates/rolldown_common/src/ecmascript/ecma_view.rs |
Removes module-wide import-meta flag. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Merging this PR will not alter performance
Comparing Footnotes
|
579cb84 to
055bdaf
Compare
055bdaf to
b7eeb99
Compare
b7eeb99 to
16a74cf
Compare
16a74cf to
85bd27b
Compare
## [1.2.12] - 2026-09-30 ### 🚀 Features - inline common chunks containing import() and deduplicate shared code in lazy chunks (#11034) by @hyfdev - experimental `inlineCommonChunks` support (#10899) by @hyfdev - dev: ship imported bindings for HMR partial accept (#10856) by @h-a-n-a ### 🐛 Bug Fixes - chunking: re-derive chunk exec orders after the runtime leaves its host chunk (#11005) by @hyfdev - code-splitting: gate member-read init paths on the reading statement (#11039) by @hyfdev - code-splitting: retain initialization paths through re-exported namespaces (#11037) by @hyfdev - dev: reject non-ESM output formats in dev mode (#11038) by @h-a-n-a - dev: align `import.meta.hot.accept` deps with Vite (#10997) by @h-a-n-a - dev: clear the resolver cache when a file is created or deleted (#10986) by @waltuov - error: name the resolved specifier in unresolved import diagnostics (#11014) by @linyiru - make entries-aware chunk merging deterministic (#11002) by @hyfdev - watch: avoid restarting macOS watcher for unchanged paths (#10992) by @sep2 ### 🚜 Refactor - dev: ship the dev runtime entry as one file (#10998) by @h-a-n-a - binding: remove `__internalForcePanic` (#10989) by @IWANABETHATGUY ### 📚 Documentation - fix cloudflare preview builds (#10996) by @sapphi-red - fix build config loader warning (#10994) by @sapphi-red - deps: use Vite 8 (#10993) by @sapphi-red ### ⚡ Performance - dev: only ship rows with dynamic edges in registerGraph (#11019) by @h-a-n-a ### 🧪 Testing - code-splitting: cover more re-exported namespace shapes (#11042) by @hyfdev - webcontainer: cover the WebContainer download fallback in plain Node (#10966) by @shulaoda - dev: pin the runtime entry file layout that Vite serves (#10983) by @h-a-n-a ### ⚙️ Miscellaneous Tasks - pin VOID_API_URL for the docs deploy (#11041) by @shulaoda - opt into the WebContainer smoke test for napi bumps and loader changes (#10967) by @shulaoda - deps: upgrade oxc to 0.152.0 (#11018) by @camc314 - deps: update rust crates (#11012) by @renovate[bot] - deps: update npm packages (#11011) by @renovate[bot] - deps: update crate-ci/typos action to v1.50.3 (#11023) by @renovate[bot] - deps: update test262 submodule for tests (#11022) by @rolldown-guard[bot] - deps: update rollup submodule for tests to v4.63.5 (#11021) by @rolldown-guard[bot] - deps: update dependency vite-plus to v1 (#11017) by @renovate[bot] - deps: update github actions (#11010) by @renovate[bot] - remove `CLAUDE.md` (#10925) by @iiio2 - verify release debug info by matching file IDs (#10988) by @IWANABETHATGUY - deps: update rollup submodule for tests to v4.63.4 (#10940) by @rolldown-guard[bot] ### ❤️ New Contributors * @waltuov made their first contribution in [#10986](#10986) * @linyiru made their first contribution in [#11014](#11014) * @sep2 made their first contribution in [#10992](#10992) Co-authored-by: shulaoda <[email protected]>

With common-chunk inlining enabled, shared loaders can remain separate files, and lazy chunks can include shared code already supplied by their importers. This PR inlines eligible shared loaders containing resolved internal
import()calls and omits redundant copies when every entry loading path provides the shared module.For an entry that uses a shared module and dynamically loads a second reader:
Before, the shared module is merged with the entry's implementation, leaving a separate file to start the entry. Simplified output:
After:
Changes
import.metarestriction only to statements retained by tree-shaking. An unused function or initializer containingimport.metadoes not keep an otherwise eligible common chunk as a file.maxSize: Infinityas an unlimited threshold.With two independent entries that each provide the shared module before loading the same lazy chunk, the shared factory count falls from three to two. Module initialization and shared state remain common to all readers.
Validation
import.meta, missing and unknown parents, nested imports, entry roots and minified output.just test-rust,just t-nodeandjust lintpassed.Stacked on #10899.