-
-
Notifications
You must be signed in to change notification settings - Fork 757
fix(mf): filter runtime plugin invocation for used exports #12807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this 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.
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-params/rspack.config.js
Show resolved
Hide resolved
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/runtime-plugin.js
Show resolved
Hide resolved
tests/rspack-test/configCases/container-1-5/runtime-plugin-with-used-exports/rspack.config.js
Show resolved
Hide resolved
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
🙈 Size remains the same at 48.01MB |
Merging this PR will not alter performance
Comparing Footnotes
|
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