core
core copied to clipboard
rspack module federation not firing onLoad and other hooks when exposed modules from other remotes are loaded
Describe the bug
rspack rewrites the import for an exposed module from a remote to a static import rather than a dynamic import using loadRemote
This is causing 2 issues:
- The lifecycle hooks like onLoad and other hooks are not triggered for the exposed modules loaded
- Once the parent remote entry is loaded, all child remote entries are loaded by default because they are static imports and not dynamic.
- This is a cause of concern as it has serious performance impact for large projects
Example:
I have 2 remotes:
- project-a
- project-b
project-a imports the button (which is an exposed module) from project-b.
import Button, { someThingElse } from 'project-b/button';
rspack converts it to this:
import * as __WEBPACK_EXTERNAL_MODULE_webpack_container_reference_project_b__ from 'https://rollup-plugin-module-federation-project-b.vercel.app/rspack/esm/my-remote-entry.js';
My rollup plugin rollup-plugin-module-federation converts it to:
const Button = (await loadRemote('project-b/button')).default;
const { someThingElse } = (await loadRemote('project-b/button'));
My implementation fixes both the bugs I mentioned above.
- Since exposed modules are loaded using
loadRemote
it fires all the hooks - Since the exposed module is actually loaded only when it's required, it doesn't trigger additional network calls when the remote for project-a is loaded
Working example:
- rspack: https://rollup-plugin-module-federation-project-a.vercel.app/rspack/esm/
- rollup: https://rollup-plugin-module-federation-project-a.vercel.app/rollup/esm/
Just click on the buttons from left to right and check the console logs and the network tabs.
Reproduction
Provided above.
Used Package Manager
npm
System Info
NA
Validations
- [X] Read the docs.
- [X] Read the common issues list.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Module federation issue and not a framework-specific issue.
- [X] The provided reproduction is a minimal reproducible example of the bug.