-
-
Notifications
You must be signed in to change notification settings - Fork 360
feat: implement standardized unload/teardown API for remote modules #4180
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
base: main
Are you sure you want to change the base?
Conversation
- Add unload hooks (beforeUnloadRemote, afterUnloadRemote) to RemoteHandler - Add public unloadRemote method to RemoteHandler with comprehensive error handling - Add unload method to ModuleFederation core class - Expose unloadRemote function in runtime package for global API access - Leverage existing comprehensive cleanup functionality in removeRemote - Provides official API to address memory leaks in long-running SPAs - Eliminates need for fragile workarounds with private Webpack APIs Fixes #4160
|
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ 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".
| async unloadRemote(remoteName: string): Promise<void> { | ||
| const { host } = this; | ||
| const remote = host.options.remotes.find( | ||
| (item) => item.name === remoteName, | ||
| ); | ||
|
|
||
| if (!remote) { |
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.
Resolve remotes by alias when unloading
The new unload API searches host.options.remotes using only remote.name. Many remotes are registered with an alias and all load requests are issued via that alias (loadRemote('alias/...')). Callers that only know the alias will invoke unloadRemote('alias') and hit the warning path, leaving the remote’s modules, cached state, and script tags intact. To keep the API symmetric with loadRemote and avoid leaked resources, the lookup should handle aliases (or reuse matchRemoteWithNameAndExpose) before deciding that a remote is unknown.
Useful? React with 👍 / 👎.
🎯 Overview
This PR implements the standardized unload/teardown API for remote modules as requested in issue #4160.
🔧 Changes Made
1. Enhanced RemoteHandler Hook System
beforeUnloadRemoteandafterUnloadRemotehooks for extensibility2. Public RemoteHandler.unloadRemote() Method
removeRemote()cleanup logic3. ModuleFederation Core Class Integration
unload(remoteName: string): Promise<void>method4. Runtime Package API
unloadRemote()function following the same pattern as other runtime functions🚀 API Usage
The implementation provides exactly what was requested in the issue:
🧹 Comprehensive Cleanup Process
The unload API leverages the existing comprehensive cleanup functionality that handles:
✅ Quality Assurance
nx build runtime-coreandnx build runtimepass🎉 Benefits Delivered
Fixes #4160