Skip to content

fix: avoid rspack runtime name conflicts - #14996

Closed
LingyuCoder wants to merge 1 commit into
mainfrom
seal/fix-rspack-export-name-conflicts
Closed

LingyuCoder wants to merge 1 commit into
mainfrom
seal/fix-rspack-export-name-conflicts

Conversation

@LingyuCoder

Copy link
Copy Markdown
Contributor

Summary

  • deconflict Rspack export runtime names per chunk and avoid reserving core runtime names for runtime-free ESM chunks
  • use the actual rspackRequire module factory argument when handling nested bindings
  • leave top-level ESM bindings to the ESM linker while preserving CJS factory parameter safety
  • add execution coverage for context, exports, local CJS rspackRequire, and runtime-free exported function names

Testing

  • corepack pnpm --filter @rspack/binding run build:dev
  • corepack pnpm --parallel --filter '@rspack/*' test\n- targeted RuntimeModeEsmOutput regression cases\n- cargo check -p rspack_plugin_esm_library -p rspack_plugin_javascript

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

Copy link
Copy Markdown

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: 0b498c0b18

ℹ️ 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".

} else {
parser.parser_runtime_requirements.require.as_str()
}
parser.parser_runtime_requirements.require.as_str()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Choose the nested name from the render mode

With experiments.runtimeMode: "rspack" and ordinary non-modern-module output, module code uses RspackContext, so the factory argument is __rspack_context while parser_runtime_requirements.require is the member expression __rspack_context.r. No declaration can match that string, leaving nested bindings named __rspack_context unchanged so they can shadow generated calls such as __rspack_context.r(...) and break a nested require(). This also regresses configCases/runtime/runtime-mode-nested-rspack-context, which explicitly expects the binding to be renamed; keep using the context name for RspackContext and use the require name only for RspackExport.

Useful? React with 👍 / 👎.

Comment on lines +33 to +35
parser.compiler_options.experiments.runtime_mode == RuntimeMode::Rspack
&& parser.is_esm
&& parser.is_top_level_scope()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit the ESM binding exemption to export rendering

When Rspack runtime mode parses an ESM source for ordinary non-modern-module output, this predicate is still true even though no ESM linker will deconflict the binding; with concatenation disabled, the module is emitted inside a factory whose parameters include __rspack_exports and __rspack_context. A top-level declaration such as const __rspack_exports = ... is therefore skipped here and emitted as a lexical redeclaration of the factory parameter, making the bundle fail to parse. Restrict this exemption to the RspackExport render mode where the ESM linker actually handles top-level bindings.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 0b498c0 to chore: migrate Rslib and Rsbuild to Rstack CLI (#14992) by Jiahan Chen

🙈 Size remains the same at 66.74MB

@github-actions

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 552.1 KB 0 0
react-10k 5.6 MB 1.3 MB 0 0
react-1k 823.1 KB 217.0 KB 0 0
react-5k 2.7 MB 663.8 KB 0 0
ui-components 4.9 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 46 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing seal/fix-rspack-export-name-conflicts (0b498c0) with main (d9d0078)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@LingyuCoder

Copy link
Copy Markdown
Contributor Author

Split into focused pull requests for easier review:

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.

1 participant