Skip to content

Comments

fix: dynamic entry merged into common chunk with cjs and esm wrap kind#7771

Merged
IWANABETHATGUY merged 1 commit intomainfrom
01-05-test_dynamic_entry_merged_into_common_chunk
Jan 7, 2026
Merged

fix: dynamic entry merged into common chunk with cjs and esm wrap kind#7771
IWANABETHATGUY merged 1 commit intomainfrom
01-05-test_dynamic_entry_merged_into_common_chunk

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Jan 6, 2026

Now test covered dynamic importee wrap kind [None, Esm, Cjs] * output format [esm, cjs], feel free to point out if I am missing any related test case

Copy link
Member Author


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@IWANABETHATGUY IWANABETHATGUY changed the title test: dynamic entry merged into common chunk fix: dynamic entry merged into common chunk Jan 6, 2026
@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 8f77854
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/695d0118e25a3000086811c1

@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit f853e7a
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/695dde97eccf10000891f5d8

@IWANABETHATGUY IWANABETHATGUY force-pushed the 01-05-test_dynamic_entry_merged_into_common_chunk branch 2 times, most recently from fc9f7b7 to 09089e3 Compare January 6, 2026 12:54
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 6, 2026

Open in StackBlitz

@rolldown/browser

npm i https://pkg.pr.new/@rolldown/browser@7771

@rolldown/debug

npm i https://pkg.pr.new/@rolldown/debug@7771

@rolldown/pluginutils

npm i https://pkg.pr.new/@rolldown/pluginutils@7771

rolldown

npm i https://pkg.pr.new/rolldown@7771

@rolldown/binding-android-arm64

npm i https://pkg.pr.new/@rolldown/binding-android-arm64@7771

@rolldown/binding-darwin-arm64

npm i https://pkg.pr.new/@rolldown/binding-darwin-arm64@7771

@rolldown/binding-darwin-x64

npm i https://pkg.pr.new/@rolldown/binding-darwin-x64@7771

@rolldown/binding-freebsd-x64

npm i https://pkg.pr.new/@rolldown/binding-freebsd-x64@7771

@rolldown/binding-linux-arm-gnueabihf

npm i https://pkg.pr.new/@rolldown/binding-linux-arm-gnueabihf@7771

@rolldown/binding-linux-arm64-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-arm64-gnu@7771

@rolldown/binding-linux-arm64-musl

npm i https://pkg.pr.new/@rolldown/binding-linux-arm64-musl@7771

@rolldown/binding-linux-x64-gnu

npm i https://pkg.pr.new/@rolldown/binding-linux-x64-gnu@7771

@rolldown/binding-linux-x64-musl

npm i https://pkg.pr.new/@rolldown/binding-linux-x64-musl@7771

@rolldown/binding-openharmony-arm64

npm i https://pkg.pr.new/@rolldown/binding-openharmony-arm64@7771

@rolldown/binding-wasm32-wasi

npm i https://pkg.pr.new/@rolldown/binding-wasm32-wasi@7771

@rolldown/binding-win32-arm64-msvc

npm i https://pkg.pr.new/@rolldown/binding-win32-arm64-msvc@7771

@rolldown/binding-win32-x64-msvc

npm i https://pkg.pr.new/@rolldown/binding-win32-x64-msvc@7771

commit: 5e24144

@IWANABETHATGUY IWANABETHATGUY force-pushed the 01-05-test_dynamic_entry_merged_into_common_chunk branch 3 times, most recently from 1f38c91 to 5e24144 Compare January 6, 2026 13:42
@IWANABETHATGUY IWANABETHATGUY changed the title fix: dynamic entry merged into common chunk fix: dynamic entry merged into common chunk with cjs and esm wrap kind Jan 6, 2026
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review January 6, 2026 16:52
@IWANABETHATGUY IWANABETHATGUY requested review from Copilot and hyf0 and removed request for Copilot January 6, 2026 16:52
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

Benchmarks Rust

  • target: main(eb312ba)
  • pr: 01-05-test_dynamic_entry_merged_into_common_chunk(f853e7a)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.02     68.7±2.20ms        ? ?/sec    1.00     67.3±2.13ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     74.4±2.56ms        ? ?/sec    1.00     74.4±1.93ms        ? ?/sec
bundle/bundle@rome_ts                                        1.01    109.2±3.25ms        ? ?/sec    1.00    107.9±1.86ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    121.3±2.11ms        ? ?/sec    1.00    121.5±1.88ms        ? ?/sec
bundle/bundle@threejs                                        1.03     39.3±1.40ms        ? ?/sec    1.00     38.2±2.62ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.00     43.4±1.10ms        ? ?/sec    1.02     44.2±1.05ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    390.0±5.00ms        ? ?/sec    1.02    396.0±7.84ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    451.9±5.89ms        ? ?/sec    1.03    464.4±6.05ms        ? ?/sec
scan/scan@rome_ts                                            1.00     83.4±1.78ms        ? ?/sec    1.02     85.0±1.84ms        ? ?/sec
scan/scan@threejs                                            1.01     28.2±1.57ms        ? ?/sec    1.00     27.9±0.56ms        ? ?/sec
scan/scan@threejs10x                                         1.00    286.3±5.49ms        ? ?/sec    1.01    290.1±4.94ms        ? ?/sec

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 a bug where dynamic entry modules merged into common chunks didn't handle CJS and ESM wrap kinds correctly. Previously, all wrapped modules were treated uniformly, but this change introduces differentiated handling based on the module's wrap kind.

Key Changes:

  • Added AST helper methods to generate appropriate Promise chain transformations for CJS and ESM wrapped modules
  • Updated export symbol tracking to include wrapper references for wrapped modules
  • Modified symbol inclusion logic to handle different wrap kinds appropriately

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
crates/rolldown_ecmascript_utils/src/ast_snippet.rs Added helper methods then_call_cjs_wrapper_with_to_esm and then_call_esm_wrapper_with_namespace to generate correct Promise chain transformations for wrapped modules
crates/rolldown/src/stages/generate_stage/compute_cross_chunk_links.rs Updated export symbol computation to differentiate between wrap kinds: CJS exports wrapper_ref only, ESM exports both wrapper_ref and namespace, None exports namespace only
crates/rolldown/src/stages/generate_stage/chunk_optimizer.rs Modified symbol inclusion and runtime helper tracking to handle different wrap kinds, conditionally including ExportAll only for non-CJS modules
crates/rolldown/src/module_finalizers/mod.rs Added wrap kind-based branching in dynamic import rewriting to generate appropriate code: __toESM(n.require_xxx()) for CJS, (n.init_xxx(), n.namespace) for ESM, and n.namespace for None
crates/rolldown/tests/rolldown/optimization/chunk_merging/dynamic_entry_merged_in_common_chunk/* Added test case for CJS wrapped module merged into common chunk with both ESM and CJS output formats
crates/rolldown/tests/rolldown/optimization/chunk_merging/dynamic_entry_merged_in_common_chunk2/* Added test case for mixed CJS and ESM wrapped modules merged into common chunk with both output formats
crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap Updated snapshot hashes reflecting the code generation changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hyf0 hyf0 mentioned this pull request Jan 7, 2026
@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 7, 2026

Merge activity

  • Jan 7, 4:18 AM UTC: IWANABETHATGUY added this pull request to the Graphite merge queue.
  • Jan 7, 4:24 AM UTC: The Graphite merge queue couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'node-test-macos / Node Test').

#7771)

Now test covered dynamic importee wrap kind `[None, Esm, Cjs]` * output format `[esm, cjs]`, feel free to point out if I am missing any related test case
@graphite-app graphite-app bot force-pushed the 01-05-test_dynamic_entry_merged_into_common_chunk branch from 5e24144 to f853e7a Compare January 7, 2026 04:18
@IWANABETHATGUY IWANABETHATGUY merged commit 8a07413 into main Jan 7, 2026
58 of 59 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the 01-05-test_dynamic_entry_merged_into_common_chunk branch January 7, 2026 04:55
@github-actions github-actions bot mentioned this pull request Jan 7, 2026
shulaoda added a commit that referenced this pull request Jan 7, 2026
## [1.0.0-beta.59] - 2026-01-07

⚡ Inline Dynamic Imports for Statically Imported Modules

- When a module is already statically imported, dynamic imports to that same module are now inlined instead of creating a separate chunk

### 🚀 Features

- plugin_timings: add 3s threshold and doc link to warning message (#7741) by @shulaoda
- improve treeshaking logic to handle empty parameter list in dynamic import .then() callbacks (#7781) by @Copilot
- dev/lazy: don't include already executed modules (#7745) by @hyf0
- dev/lazy: support dynamic `import(..)` (#7726) by @hyf0
- inline dynamic imports that imports statically imported modules (#7742) by @IWANABETHATGUY
- option: add experimental option to control chunk optimization (#7738) by @IWANABETHATGUY

### 🐛 Bug Fixes

- inline dynamic entry to user defined entry with esm wrap kind (#7783) by @IWANABETHATGUY
- use canonical namespace reference for property access (#7777) by @IWANABETHATGUY
- dynamic entry merged into common chunk with cjs and esm wrap kind (#7771) by @IWANABETHATGUY
- tla: should not await non-tla-related modules (#7768) by @hyf0
- dynamic entry captured by common chunk with CJS format (#7757) by @IWANABETHATGUY
- module_loader: mark emitted chunks as user-defined entry when already loaded (#7765) by @shulaoda
- normalize preserveModulesRoot path (#7737) by @IWANABETHATGUY
- linker: resolve race condition in side effects computation for export-star (#7728) by @camc314

### 🚜 Refactor

- plugin_timings: filter out plugins with duration < 1s from timing warnings (#7785) by @shulaoda
- module_loader: remove unnecessary collect before extend (#7769) by @shulaoda
- rename _id suffixes to _idx for oxc_index types (#7767) by @IWANABETHATGUY
- remove duplicate `preserve_entry_signatures` from `AddEntryModuleMsg` (#7762) by @shulaoda
- module_loader: pass `user_defined_entries` by reference (#7756) by @shulaoda
- dev/lazy: get proxy entry's `ResolvedId` correctly (#7746) by @hyf0
- simplify try_rewrite_import_expression control flow (#7753) by @IWANABETHATGUY
- module_loader: remove unnecessary dynamic import handling for runtime module (#7754) by @shulaoda
- inline __toDynamicImportESM  (#7747) by @IWANABETHATGUY
- use From impl for ModuleLoaderOutput conversion (#7732) by @shulaoda
- remove duplicate fields from `ModuleLoader` (#7731) by @shulaoda
- tweak `resolve_user_defined_entries` (#7727) by @shulaoda

### 📚 Documentation

- add rolldown-string reference to native MagicString compatibility section (#7778) by @Copilot
- improve comments for export star side effects handling (#7730) by @IWANABETHATGUY

### 🧪 Testing

- use assertion instead of console.log for some testcase (#7744) by @IWANABETHATGUY

### ⚙️ Miscellaneous Tasks

- tweak some `output.dynamicImportInCjs` related rollup test results (#7776) by @sapphi-red
- mark esbuild/dce/dce_of_symbol_ctor_call as passed (#7775) by @sapphi-red
- deps: update oxc apps (#7772) by @renovate[bot]
- vite-tests: allow running on PRs with `test: vite-tests` label (#7770) by @shulaoda
- deps: update oxc apps (#7760) by @renovate[bot]
- deps: update rollup submodule for tests to v4.55.1 (#7763) by @sapphi-red
- deps: update test262 submodule for tests (#7764) by @sapphi-red
- deps: update oxc to v0.107.0 (#7758) by @camc314
- deps: update taiki-e/install-action action to v2.65.13 (#7751) by @renovate[bot]
- deps: update rust crates (#7750) by @renovate[bot]
- deps: update npm packages (#7749) by @renovate[bot]
- deps: update github-actions (#7748) by @renovate[bot]
- deps: update dependency oxlint-tsgolint to v0.10.1 (#7729) by @renovate[bot]
- deps: update crate-ci/typos action to v1.41.0 (#7725) by @renovate[bot]

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants