Skip to content

Comments

fix: fallback sourcemap generation for experimental.nativeMagicString: false#6488

Merged
graphite-app[bot] merged 1 commit intomainfrom
10-12-fix_fallback_mode_for_nativemagicstring_false_
Oct 12, 2025
Merged

fix: fallback sourcemap generation for experimental.nativeMagicString: false#6488
graphite-app[bot] merged 1 commit intomainfrom
10-12-fix_fallback_mode_for_nativemagicstring_false_

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Oct 12, 2025

TL;DR

Added an experimental flag to control native MagicString sourcemap generation, allowing for both native and JavaScript-based sourcemap generation paths.
Sometimes on the JS side, users require that the sourcemap generation be synced, e.g.

public getCombinedSourcemap(): SourceMap {
return JSON.parse(this.inner.getCombinedSourcemap());
}

What changed?

  • Added an experimental flag nativeMagicString to control whether sourcemap generation happens in native Rust code or in JavaScript
  • Modified the ScanStage to conditionally create the sourcemap generation thread based on this flag
  • Updated the TransformPluginContext.send_magic_string method to return the sourcemap JSON string when native mode is disabled
  • Updated the JavaScript binding to handle both modes, using the returned sourcemap when in JavaScript mode
  • Added test fixtures for both enabled and disabled native MagicString modes

How to test?

  1. Run the new test fixtures:

    • packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-true
    • packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-false
  2. Verify that sourcemaps are correctly generated in both modes.

  3. Test with a real project by setting the experimental flag:

    // rolldown.config.js
    export default {
      experimental: {
        nativeMagicString: true, // or false
      },
      // other config
    }

Why make this change?

This change provides flexibility in how sourcemaps are generated, allowing for both native (Rust-based) and JavaScript-based approaches. This can be useful for debugging, performance testing, or compatibility purposes. The experimental flag allows users to choose the approach that works best for their specific use case.

Copy link
Member Author

IWANABETHATGUY commented Oct 12, 2025


How to use the Graphite Merge Queue

Add the label graphite: merge 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 force-pushed the 10-12-fix_fallback_mode_for_nativemagicstring_false_ branch from 7693f5b to fc253e5 Compare October 12, 2025 15:48
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review October 12, 2025 15:48
@IWANABETHATGUY IWANABETHATGUY changed the title fix: fallback mode for nativeMagicString: false fix: fallback sourcemap generation for experimental.nativeMagicString: false Oct 12, 2025
@IWANABETHATGUY IWANABETHATGUY force-pushed the 10-09-feat_add_nativemagicstring_options branch from e1e6b28 to 9fe7b4a Compare October 12, 2025 15:52
@IWANABETHATGUY IWANABETHATGUY force-pushed the 10-12-fix_fallback_mode_for_nativemagicstring_false_ branch 4 times, most recently from 59a4736 to 501b6c2 Compare October 12, 2025 16:02
@IWANABETHATGUY IWANABETHATGUY force-pushed the 10-09-feat_add_nativemagicstring_options branch from 9fe7b4a to f817d69 Compare October 12, 2025 16:02
@graphite-app graphite-app bot changed the base branch from 10-09-feat_add_nativemagicstring_options to graphite-base/6488 October 12, 2025 16:15
@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 12, 2025

Merge activity

@github-actions
Copy link
Contributor

github-actions bot commented Oct 12, 2025

Benchmarks Rust

  • target: main(f2892b4)
  • pr: 10-12-fix_fallback_mode_for_nativemagicstring_false_(871e5e8)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     65.3±1.34ms        ? ?/sec    1.02     66.4±1.17ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     72.0±1.25ms        ? ?/sec    1.02     73.3±1.89ms        ? ?/sec
bundle/bundle@rome_ts                                        1.00    109.0±1.84ms        ? ?/sec    1.01    109.8±1.91ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    124.9±2.35ms        ? ?/sec    1.01    126.0±1.53ms        ? ?/sec
bundle/bundle@threejs                                        1.01     43.5±2.83ms        ? ?/sec    1.00     42.8±1.00ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.01     50.4±1.38ms        ? ?/sec    1.00     50.1±0.70ms        ? ?/sec
bundle/bundle@threejs10x                                     1.00    424.0±4.10ms        ? ?/sec    1.00    425.8±6.21ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.00    487.7±3.69ms        ? ?/sec    1.00    490.1±3.18ms        ? ?/sec
scan/scan@rome_ts                                            1.02     88.3±2.30ms        ? ?/sec    1.00     86.4±1.51ms        ? ?/sec
scan/scan@threejs                                            1.00     32.4±0.40ms        ? ?/sec    1.00     32.2±1.00ms        ? ?/sec
scan/scan@threejs10x                                         1.01    336.6±4.22ms        ? ?/sec    1.00    331.8±3.95ms        ? ?/sec

@graphite-app graphite-app bot changed the base branch from graphite-base/6488 to main October 12, 2025 16:29
graphite-app bot pushed a commit that referenced this pull request Oct 12, 2025
…g: false` (#6488)

### TL;DR

Added an experimental flag to control native MagicString sourcemap generation, allowing for both native and JavaScript-based sourcemap generation paths.
Sometimes on the JS side, users require that the sourcemap generation be **synced**, e.g.
https://github.com/rolldown/rolldown/blob/79fa18fdc978d4babf4c6ec45225b2802e38ddc9/packages/rolldown/src/plugin/transform-plugin-context.ts?plain=1#L80-L82

### What changed?

- Added an experimental flag `nativeMagicString` to control whether sourcemap generation happens in native Rust code or in JavaScript
- Modified the `ScanStage` to conditionally create the sourcemap generation thread based on this flag
- Updated the `TransformPluginContext.send_magic_string` method to return the sourcemap JSON string when native mode is disabled
- Updated the JavaScript binding to handle both modes, using the returned sourcemap when in JavaScript mode
- Added test fixtures for both enabled and disabled native MagicString modes

### How to test?

1. Run the new test fixtures:
   - `packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-true`
   - `packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-false`

2. Verify that sourcemaps are correctly generated in both modes.

3. Test with a real project by setting the experimental flag:
   ```js
   // rolldown.config.js
   export default {
     experimental: {
       nativeMagicString: true, // or false
     },
     // other config
   }
   ```

### Why make this change?

This change provides flexibility in how sourcemaps are generated, allowing for both native (Rust-based) and JavaScript-based approaches. This can be useful for debugging, performance testing, or compatibility purposes. The experimental flag allows users to choose the approach that works best for their specific use case.
@graphite-app graphite-app bot force-pushed the 10-12-fix_fallback_mode_for_nativemagicstring_false_ branch from 501b6c2 to 5e1828b Compare October 12, 2025 16:30
@netlify
Copy link

netlify bot commented Oct 12, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 871e5e8
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/68ebdc1acd026800084109cb
😎 Deploy Preview https://deploy-preview-6488--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

…g: false` (#6488)

### TL;DR

Added an experimental flag to control native MagicString sourcemap generation, allowing for both native and JavaScript-based sourcemap generation paths.
Sometimes on the JS side, users require that the sourcemap generation be **synced**, e.g.
https://github.com/rolldown/rolldown/blob/79fa18fdc978d4babf4c6ec45225b2802e38ddc9/packages/rolldown/src/plugin/transform-plugin-context.ts?plain=1#L80-L82

### What changed?

- Added an experimental flag `nativeMagicString` to control whether sourcemap generation happens in native Rust code or in JavaScript
- Modified the `ScanStage` to conditionally create the sourcemap generation thread based on this flag
- Updated the `TransformPluginContext.send_magic_string` method to return the sourcemap JSON string when native mode is disabled
- Updated the JavaScript binding to handle both modes, using the returned sourcemap when in JavaScript mode
- Added test fixtures for both enabled and disabled native MagicString modes

### How to test?

1. Run the new test fixtures:
   - `packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-true`
   - `packages/rolldown/tests/fixtures/output/sourcemap/native-magic-string-false`

2. Verify that sourcemaps are correctly generated in both modes.

3. Test with a real project by setting the experimental flag:
   ```js
   // rolldown.config.js
   export default {
     experimental: {
       nativeMagicString: true, // or false
     },
     // other config
   }
   ```

### Why make this change?

This change provides flexibility in how sourcemaps are generated, allowing for both native (Rust-based) and JavaScript-based approaches. This can be useful for debugging, performance testing, or compatibility purposes. The experimental flag allows users to choose the approach that works best for their specific use case.
@graphite-app graphite-app bot force-pushed the 10-12-fix_fallback_mode_for_nativemagicstring_false_ branch from 5e1828b to 871e5e8 Compare October 12, 2025 16:49
@graphite-app graphite-app bot merged commit 871e5e8 into main Oct 12, 2025
28 checks passed
@graphite-app graphite-app bot deleted the 10-12-fix_fallback_mode_for_nativemagicstring_false_ branch October 12, 2025 17:26
shulaoda pushed a commit that referenced this pull request Oct 13, 2025
## [1.0.0-beta.43] - 2025-10-13

### 🚀 Features

- add filterVitePlugins utility that uses to skip vite plugins using apply: "serve" (#6502) by @IWANABETHATGUY
- rolldown_plugin_vite_html: align partial can inline entry logic (#6500) by @shulaoda
- rolldown_plugin_vite_html: align get_imported_chunks logic (#6499) by @shulaoda
- rolldown_plugin_vite_html: align HtmlTagDescriptor (#6498) by @shulaoda
- rolldown_plugin_vite_html: align partial utility functions logic (#6497) by @shulaoda
- rolldown_html_vite_html: align partial inject chunk asset links logic (#6496) by @shulaoda
- rolldown_plugin_vite_html: align `processedHtml` logic (#6494) by @shulaoda
- add `nativeMagicString` options (#6469) by @IWANABETHATGUY
- rust: eagerly cleanup resources when calling `close` (#6483) by @hyf0
- rust: varify if bundler is closed for public API (#6481) by @hyf0
- replace [format] placeholder in chunk filename templates (#6476) by @elecmonkey
- implement synchronous JS callback invocation for paths function (#6474) by @IWANABETHATGUY
- rolldown_plugin_vite_html: align partial transform hook logic (#6471) by @shulaoda
- Support `output.paths` (#6470) by @IWANABETHATGUY
- rolldown_plugin_vite_html: align script urls handle logic (#6466) by @shulaoda
- add validation for `preserveEntrySignatures` with `includeDependenciesRecursively` option (#6468) by @hyf0
- rolldown_plugin_vite_html: align partial logic (#6465) by @shulaoda
- background sourcemap generation for Javascript transform hooks (#6293) by @IWANABETHATGUY
- rolldown_plugin_vite_html: handle style tag (#6464) by @shulaoda
- rolldown_plugin_vite_html: handle inline style attribute (#6463) by @shulaoda
- rolldown_plugin_vite_html: patially handle vite-ignore attribute (#6462) by @shulaoda
- dev/node: expose errors of `on_hmr_updatrs` to node (#6454) by @hyf0
- dev/node: expose errors of `on_output` to node (#6453) by @hyf0
- dev: expose hmr errors on `on_hmr_updatrs` callback (#6443) by @hyf0

### 🐛 Bug Fixes

- fallback sourcemap generation for `experimental.nativeMagicString: false` (#6488) by @IWANABETHATGUY
- take `resolve.modules` into account (#6484) by @Pickachu
- rolldown: increase tokio blocking threads size for watch mode (#6467) by @Brooooooklyn
- use len_utf16 in magic_string CharToByteMapper (#6461) by @IWANABETHATGUY
- pass `advancedChunks#includeDependenciesRecursively` to rust (#6448) by @hyf0
- dev: should compute hmr update correctly for multiple clients (#6442) by @hyf0
- allow specifying packageJsonPath in PluginContext.load (#6439) by @sapphi-red
- use transform.target as default for minify target when `minify: { compress: true }` (#6433) by @sapphi-red

### 🚜 Refactor

- extract background sourcemap handling into separate methods (#6501) by @IWANABETHATGUY
- rust: only expose methods of `Bundler` for public usage (#6480) by @hyf0
- dev/node: use napi object instead clss for `BindingClientHmrUpdate` (#6456) by @hyf0
- dev/node: improve `DevOnHmrUpdates` API (#6455) by @hyf0

### 📚 Documentation

- update team page and add acknowledgements page (#6495) by @hyf0
- restructure website and files (#6492) by @hyf0
- correct incorrect documentation about the config file (#6472) by @jsparkdev
- options: `experimental.strictExecutionOrder` (#6450) by @hyf0
- adding `why-plugin-hook-filter` in depth (#6446) by @IWANABETHATGUY

### ⚡ Performance

- rolldown: replace serde JSON string escape with simd impl (#6475) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- docs: redirect removed path to new locations for compatibility (#6493) by @hyf0
- deps: lock file maintenance npm packages (#6490) by @renovate[bot]
- deps: update github-actions (major) (#6415) by @renovate[bot]
- deps: update github-actions (#6489) by @renovate[bot]
- rust: add comment for `DiagnosticOptions#stabilize_path` (#6447) by @hyf0
- rust: remove unused `BindingHmrOutput` (#6457) by @hyf0
- rolldown_plugin_vite_html: tweak `utils.rs` (#6460) by @shulaoda
- change node version to lts (#6435) by @iiio2
- rust/test: split hmr related structs into their own files (#6445) by @hyf0
- deps: update crate-ci/typos action to v1.38.1 (#6452) by @renovate[bot]
- rust/test: render hmr errors (#6444) by @hyf0
- examples: add `"type": "module"` in `package.json` (#6441) by @iiio2

### ❤️ New Contributors

* @Pickachu made their first contribution in [#6484](#6484)
* @elecmonkey made their first contribution in [#6476](#6476)
* @jsparkdev made their first contribution in [#6472](#6472)
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.

2 participants