Skip to content

fix(esm-library): avoid duplicate __webpack_require__ export#13483

Merged
JSerFeng merged 2 commits into
web-infra-dev:mainfrom
JSerFeng:fy/fix-duplicate-runtime-export
Mar 27, 2026
Merged

fix(esm-library): avoid duplicate __webpack_require__ export#13483
JSerFeng merged 2 commits into
web-infra-dev:mainfrom
JSerFeng:fy/fix-duplicate-runtime-export

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

Summary

  • avoid adding __webpack_require__ to chunk_link.exports when module chunk loading will export it via runtime module
  • record that export strategy in ChunkLinkContext during link and let render consume link metadata instead of scanning runtime modules
  • add an esmOutputCases regression for runtimeChunk: false with a shared CJS chunk, which reproduces the duplicate export failure without the fix

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings March 26, 2026 09:29
@github-actions github-actions Bot added the release: bug fix release: bug related release(mr only) label Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 26, 2026

📝 Ecosystem CI detail: Open

suite result
rspress ✅ success
modernjs ✅ success
examples ✅ success
rsbuild ✅ success
rsdoctor ✅ success
lynx-stack ❌ failure
rsbuild-rsc-plugin ✅ success
devserver ✅ success
rslib ✅ success
rstest ✅ success
plugin ✅ success

@JSerFeng
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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 fixes a duplicate __webpack_require__ ESM export that can occur in modern-module / ESM library output, especially when optimization.runtimeChunk: false causes entry chunks to carry runtime and be imported by other chunks.

Changes:

  • Avoids adding __webpack_require__ to ESM-library chunk exports when ExportRequireRuntimeModule will already export it.
  • Records the export strategy on ChunkLinkContext during link, and uses that metadata during render instead of scanning runtime modules.
  • Adds a regression esmOutputCases test for runtimeChunk: false with a shared CJS module to reproduce the duplicate-export failure.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rspack_plugin_runtime/src/helpers.rs Adds a shared helper to decide when module chunk loading should export __webpack_require__.
crates/rspack_plugin_runtime/src/module_chunk_loading.rs Uses the shared helper to keep the export decision consistent across runtime requirements hooks.
crates/rspack_plugin_esm_library/src/chunk_link.rs Extends ChunkLinkContext with exports_require_via_runtime_module metadata.
crates/rspack_plugin_esm_library/src/link.rs Sets the new link metadata and prevents adding a redundant __webpack_require__ chunk export in the affected cases.
crates/rspack_plugin_esm_library/src/render.rs Consumes link metadata to decide whether to emit a direct __webpack_require__ export.
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/shared.js Adds a shared CJS module used by both the entry and a dynamically imported module.
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/dynamic.js Dynamic import path that consumes the shared CJS module.
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/index.js Entry test that exports a value and triggers the problematic runtime/export interaction.
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/rspack.config.js Overrides optimization.runtimeChunk to false to reproduce the issue.
tests/rspack-test/esmOutputCases/dynamic-import/import-cjs-runtime-chunk-false-entry-export/__snapshots__/esm.snap.txt Captures the corrected output (single __webpack_require__ export) for regression coverage.

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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 27, 2026

Merging this PR will degrade performance by 2.87%

⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 19 untouched benchmarks
⏩ 3 skipped benchmarks1

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation js@Traverse module graph by connections 279.8 µs 262.5 µs +6.59%
Simulation js@Traverse module graph by dependencies 528.1 µs 543.7 µs -2.87%
Memory bundle@threejs-production-sourcemap 48.7 MB 49.7 MB -1.96%
Memory bundle@threejs-development 19.5 MB 19.8 MB -1.42%

Comparing JSerFeng:fy/fix-duplicate-runtime-export (0b918d9) with main (418eeeb)

Open in CodSpeed

Footnotes

  1. 3 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.

@JSerFeng JSerFeng merged commit bb4017e into web-infra-dev:main Mar 27, 2026
36 checks passed
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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants