Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

Summary

Render runtime root variables like __webpack_require__/__webpack_modules__/__webpack_module_cache__ by runtime template.

Related links

Checklist

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

Copilot AI review requested due to automatic review settings November 27, 2025 05:29
@netlify
Copy link

netlify bot commented Nov 27, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 89f5ae0
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6927e8cd9d0f5d000855adfd

@github-actions github-actions bot added release: refactor team The issue/pr is created by the member of Rspack. labels Nov 27, 2025
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 refactors the codebase to use a template-based approach for rendering runtime root variables (like __webpack_require__, __webpack_modules__, __webpack_module_cache__, __webpack_exports__) instead of hardcoded strings. This is achieved by introducing a new RuntimeVariable enum and corresponding render_runtime_variable() method on RuntimeTemplate.

Key changes:

  • Added RuntimeVariable enum with variants for common runtime variables (Require, Modules, ModuleCache, Module, Exports, EsmChunkIds, EsmChunkId, EsmRuntime)
  • Introduced render_runtime_variable(), render_exports_argument(), and render_module_argument() methods on RuntimeTemplate
  • Removed Display trait implementations from ModuleArgument and ExportsArgument enums in favor of the new rendering methods
  • Updated all callsites across plugins to use the new template-based rendering approach

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/rspack_core/src/runtime_globals.rs Added RuntimeVariable enum and runtime_variable_to_string() function; updated runtime_globals_to_string() to use the new function
crates/rspack_core/src/runtime_template.rs Added render_runtime_variable(), render_exports_argument(), and render_module_argument() methods
crates/rspack_core/src/module.rs Removed Display trait implementations for ModuleArgument and ExportsArgument
crates/rspack_core/src/lib.rs Exported RuntimeVariable alongside RuntimeGlobals
crates/rspack_plugin_runtime/src/runtime_module/export_require.rs Removed hardcoded constant and now dynamically generates temporary variable name
crates/rspack_plugin_runtime/src/runtime_module/module_chunk_loading.rs Updated to use render_runtime_variable() for ESM chunk IDs, modules, and runtime
crates/rspack_plugin_runtime/src/runtime_module/make_deferred_namespace_object_runtime.rs Updated to use render_runtime_variable() for module cache
crates/rspack_plugin_runtime/src/runtime_module/async_module.rs Updated to use render_runtime_variable() for module cache
crates/rspack_plugin_runtime/src/module_chunk_format.rs Updated to use render_runtime_variable() for ESM chunk variables, modules, runtime, and exports
crates/rspack_plugin_runtime/src/helpers.rs Updated to use render_runtime_variable() for exports in entry startup generation
crates/rspack_plugin_runtime/src/array_push_callback_chunk_format.rs Updated to use render_runtime_variable() for exports
crates/rspack_plugin_library/src/module_library_plugin.rs Updated to use render_runtime_variable() for exports
crates/rspack_plugin_library/src/modern_module_library_plugin.rs Updated to use render_runtime_variable() for exports
crates/rspack_plugin_library/src/assign_library_plugin.rs Updated to use render_runtime_variable() for exports; has duplicate variable declaration
crates/rspack_plugin_javascript/src/runtime.rs Updated to use render_module_argument() and render_exports_argument()
crates/rspack_plugin_javascript/src/plugin/mod.rs Updated to use render_runtime_variable(), render_module_argument(), and render_exports_argument() throughout
crates/rspack_plugin_javascript/src/dependency/module_argument_dependency.rs Updated to use render_module_argument()
crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs Updated to use render_exports_argument()
crates/rspack_plugin_javascript/src/dependency/esm/esm_export_expression_dependency.rs Updated to use render_exports_argument()
crates/rspack_plugin_javascript/src/dependency/esm/esm_compatibility_dependency.rs Updated to use render_exports_argument() and render_module_argument()
crates/rspack_plugin_javascript/src/dependency/commonjs/module_decorator_dependency.rs Updated to use render_module_argument()
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_self_reference_dependency.rs Updated to use render_exports_argument() and render_module_argument()
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_exports_dependency.rs Updated to use render_exports_argument() and render_module_argument()
crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs Updated to use render_exports_argument() and render_module_argument()
crates/rspack_plugin_esm_library/src/render.rs Updated to use render_runtime_variable() for modules and module cache
crates/rspack_core/src/init_fragment.rs Updated to use render_exports_argument()
crates/rspack_core/src/concatenated_module.rs Updated to use render_exports_argument()
tests/rspack-test/esmOutputCases/split-chunks/export-temp-runtime/__snapshots__/esm.snap.txt Updated snapshot showing corrected temporary variable naming

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

📦 Binary Size-limit

Comparing 89f5ae0 to chore(deps): update dependency @microsoft/api-extractor-model to v7.32.1 (#12292) by renovate[bot]

❌ Size increased by 9.63KB from 47.67MB to 47.68MB (⬆️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 27, 2025

CodSpeed Performance Report

Merging #12308 will not alter performance

Comparing refactor/render-root-variables (89f5ae0) with main (6ee567e)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder requested a review from ahabhgk November 27, 2025 06:23
@LingyuCoder LingyuCoder merged commit 4322519 into main Nov 27, 2025
47 checks passed
@LingyuCoder LingyuCoder deleted the refactor/render-root-variables branch November 27, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants