Skip to content

fix: render numeric chunk IDs as number literals#13604

Open
JSerFeng wants to merge 12 commits intomainfrom
fix/numeric-chunk-id-rendering
Open

fix: render numeric chunk IDs as number literals#13604
JSerFeng wants to merge 12 commits intomainfrom
fix/numeric-chunk-id-rendering

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

@JSerFeng JSerFeng commented Apr 3, 2026

Summary

  • Webpack emits numeric chunk IDs without quotes (e.g. push([[903],) while rspack wraps them in quotes (push([["903"],), causing unnecessary output bytes
  • Add json_stringify_chunk_id() helper in rspack_util that renders valid non-negative integer IDs as number literals and falls back to JSON strings for named chunks (e.g. "main")
  • Update all chunk ID rendering call sites across JSONP, CJS, ESM, CSS, worker, and SRI chunk formats

Test plan

  • cargo check passes
  • Full dev build (pnpm run build:cli:dev) succeeds
  • Verified on react-5k benchmark: all 15 async chunks now use numeric IDs (push([[106],) with zero quoted numeric IDs remaining
  • CI snapshot tests may need updating (UPDATE=1)

Copilot AI review requested due to automatic review settings April 3, 2026 09:18
@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Apr 3, 2026
@JSerFeng JSerFeng enabled auto-merge (squash) April 3, 2026 09:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be547257fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
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 reduces runtime bundle size by emitting numeric chunk IDs as JavaScript number literals (matching webpack’s output) instead of always emitting them as quoted JSON strings.

Changes:

  • Added rspack_util::json_stringify_chunk_id() to emit digit-only, non-negative integer chunk IDs without quotes.
  • Updated multiple runtime/chunk-format code paths (CJS/ESM/JSONP/CSS/worker/SRI) to use the new chunk ID stringifier.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rspack_util/src/lib.rs Adds json_stringify_chunk_id() + numeric-ID detection helper.
crates/rspack_plugin_sri/src/runtime.rs Uses json_stringify_chunk_id() for SRI placeholder map keys.
crates/rspack_plugin_runtime/src/runtime_module/utils.rs Emits chunk-id keyed maps with numeric literals when possible.
crates/rspack_plugin_runtime/src/module_chunk_format.rs Emits ESM chunk id exports using the new chunk-id stringifier.
crates/rspack_plugin_runtime/src/common_js_chunk_format.rs Emits exports.ids with numeric literals where possible.
crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs Emits JSONP push chunk IDs as numeric literals where possible.
crates/rspack_plugin_javascript/src/dependency/worker/mod.rs Embeds worker chunk id using json_stringify_chunk_id().
crates/rspack_plugin_extract_css/src/runtime.rs Emits CSS runtime chunk-id keyed maps with numeric literals where possible.
Comments suppressed due to low confidence (1)

crates/rspack_plugin_runtime/src/module_chunk_format.rs:151

  • chunk_id_json_string is now produced by json_stringify_chunk_id, which may return a number literal (e.g. 903) rather than a JSON string. Renaming this variable to something like chunk_id_expr/chunk_id_literal would better reflect its contents and avoid confusion at future call sites.
  let base_chunk_output_name = get_chunk_output_name(chunk, compilation).await?;

  let chunk_id_json_string = rspack_util::json_stringify_chunk_id(chunk.expect_id().as_str());

  let mut sources = ConcatSource::default();
  sources.add(RawStringSource::from(format!(
    "export const __rspack_esm_id = {chunk_id_json_string};\n",

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB 0
react-10k 5.7 MB -64.0 B (-0.0%)
react-1k 826.2 KB -22.0 B (-0.0%)
rome 984.1 KB 0
react-5k 2.7 MB -64.0 B (-0.0%)
ui-components 5.0 MB 0
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

📌 Baseline Commit: e26bca5966 | PR: #13700

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB -64.0 B (-0.0%)
📄 JavaScript 5.7 MB 5.7 MB -64.0 B (-0.0%)
🎨 CSS 21.0 B 21.0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

📌 Baseline Commit: e26bca5966 | PR: #13700

Metric Current Baseline Change
📊 Total Size 826.2 KB 826.2 KB -22.0 B (-0.0%)
📄 JavaScript 826.2 KB 826.2 KB -22.0 B (-0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

📌 Baseline Commit: e26bca5966 | PR: #13700

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB -64.0 B (-0.0%)
📄 JavaScript 2.7 MB 2.7 MB -64.0 B (-0.0%)
🎨 CSS 21.0 B 21.0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: react-5k Bundle Diff

Generated by Rsdoctor GitHub Action

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 3, 2026

Merging this PR will degrade performance by 3.27%

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 26 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@persistent_cache_restore@basic-react-development 26.8 ms 26 ms +3.14%
Simulation rust@create_chunk_ids 10.2 ms 10.6 ms -3.27%

Comparing fix/numeric-chunk-id-rendering (5b81c87) with main (e26bca5)

Open in CodSpeed

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

📦 Binary Size-limit

Comparing 5b81c87 to feat: expose jsonp template plugin (#13700) by Gengkun

❌ Size increased by 6.53KB from 49.39MB to 49.39MB (⬆️0.01%)

@JSerFeng JSerFeng requested a review from ahabhgk as a code owner April 3, 2026 10:03
@JSerFeng JSerFeng force-pushed the fix/numeric-chunk-id-rendering branch from bc8ef1f to ba9dd59 Compare April 8, 2026 07:31
Webpack emits numeric chunk IDs without quotes (e.g. `push([[903],`)
while rspack was wrapping them in quotes (`push([["903"],`). This
caused unnecessary bytes in every chunk file.

Add `json_stringify_chunk_id()` that renders valid non-negative integer
IDs as number literals and falls back to JSON strings for named chunks.
Update all chunk ID rendering call sites across JSONP, CJS, ESM, CSS,
worker, and SRI formats.
Address review feedback:
- Fix __rspack_require__.e() to pass numeric chunk IDs (was "903",
  now 903), ensuring type consistency with runtime === comparisons
- Add MAX_SAFE_INTEGER bound check to prevent precision loss
- Add json_stringify_chunk_ids() helper for array rendering
- Fix missed call sites in CSS plugin, MF plugin, startup chunk
  dependencies, and chunk prefetch startup
- Add unit tests for is_numeric_id and json_stringify_chunk_id
- Rename chunk_id_json_string to chunk_id_expr for clarity
- Update 9 hot snapshot files and 2 watcher test assertions
@JSerFeng JSerFeng force-pushed the fix/numeric-chunk-id-rendering branch from ba9dd59 to 510a74f Compare April 13, 2026 03:38
@JSerFeng
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@JSerFeng
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 843161438d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants