Skip to content

Conversation

@ahabhgk
Copy link
Contributor

@ahabhgk ahabhgk commented Jan 21, 2026

Summary

When usedExports optimization is enabled, runtime plugin imports may be tree-shaken to undefined. This change add a filter for plugins invocation to avoid calling undefined as a function

fix #12605

Related links

Checklist

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

When usedExports optimization is enabled, runtime plugin imports may be
tree-shaken to undefined. This change defers plugin invocation by first
collecting plugin references and params as objects, then filtering out
undefined plugins before invoking them.
@ahabhgk ahabhgk requested a review from hardfist as a code owner January 21, 2026 10:15
Copilot AI review requested due to automatic review settings January 21, 2026 10:15
@netlify
Copy link

netlify bot commented Jan 21, 2026

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 2ad2fcb
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6970a734e8c584000848fe4e

@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 Jan 21, 2026
@ahabhgk ahabhgk enabled auto-merge (squash) January 21, 2026 10:16
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 fixes a bug where runtime plugins could fail when the usedExports optimization is enabled in rspack. When tree-shaking is active, unused exports are removed and may become undefined, causing runtime errors when the code attempts to invoke them as functions.

Changes:

  • Modified the runtime plugin initialization to wrap plugins in objects containing both the plugin and its parameters
  • Added a filter step to remove undefined plugins (those tree-shaken away) before invocation
  • Added comprehensive test case covering the bug scenario with workers and Module Federation runtime plugins

Reviewed changes

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

Show a summary per file
File Description
packages/rspack/src/container/ModuleFederationPlugin.ts Core fix: wraps runtime plugins in objects and adds filter/map chain to remove undefined plugins before invocation
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/rspack.config.js Test configuration enabling usedExports optimization with runtime plugins
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/index.js Test assertions verifying plugin functionality and worker communication
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/bootstrap.js Test helper setting up React import and worker for testing tree-shaking scenario
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/worker.js Worker implementation for testing concurrent execution with tree-shaking
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/runtime-plugin.js Sample runtime plugin that overrides React dependency resolution
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/node_modules/react.js Mock React module for testing dependency resolution
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-params/rspack.config.js Removed unused output configuration and adjusted indentation
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-params/index.js Fixed indentation to be consistent with tabs throughout the file

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

@github-actions
Copy link
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
react-5k 2.7 MB 0
ui-components 2.1 MB 0
rome 984.2 KB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

📦 Binary Size-limit

Comparing 2ad2fcb to refactor: to use &Compilation in AdditionalTreeRuntimeRequirementsHook (#12801) by pshu

🙈 Size remains the same at 48.01MB

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 21, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing fix-mf-runtime-plugin-used-exports (2ad2fcb) with main (e673e53)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@ahabhgk ahabhgk merged commit e31ee70 into main Jan 21, 2026
89 of 91 checks passed
@ahabhgk ahabhgk deleted the fix-mf-runtime-plugin-used-exports branch January 21, 2026 12:05
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

3 participants