-
-
Notifications
You must be signed in to change notification settings - Fork 435
fix(runtime-core): resolve remote runtime instance identity explicitly during removal #5029
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@module-federation/runtime-core': patch | ||
| --- | ||
|
|
||
| removeRemote now also matches the remote's runtime instance by entryGlobalName and warns when no instance can be found, instead of silently leaving stale instances in __FEDERATION__.__INSTANCES__ after registerRemotes({ force: true }). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -762,17 +762,29 @@ export class RemoteHandler { | |
| let remoteInsId = remoteInfo.buildVersion | ||
| ? composeKeyWithSeparator(remoteInfo.name, remoteInfo.buildVersion) | ||
| : remoteInfo.name; | ||
| const remoteInsIndex = | ||
| CurrentGlobal.__FEDERATION__.__INSTANCES__.findIndex((ins) => { | ||
| if (remoteInfo.buildVersion) { | ||
| return ins.options.id === remoteInsId; | ||
| } else { | ||
| return ins.name === remoteInsId; | ||
| } | ||
| }); | ||
| const instances = CurrentGlobal.__FEDERATION__.__INSTANCES__; | ||
| let remoteInsIndex = instances.findIndex((ins) => { | ||
| if (remoteInfo.buildVersion) { | ||
| return ins.options.id === remoteInsId; | ||
| } else { | ||
| return ins.name === remoteInsId; | ||
| } | ||
| }); | ||
| // The registered name may differ from the name the remote was built | ||
| // with. The remote's runtime instance is named after its build name, | ||
| // which for enhanced/webpack containers equals entryGlobalName. | ||
| const { entryGlobalName } = remoteInfo; | ||
| const canMatchByEntryGlobalName = | ||
| typeof entryGlobalName === 'string' && | ||
| entryGlobalName !== '' && | ||
| entryGlobalName !== remoteInfo.name; | ||
| if (remoteInsIndex === -1 && canMatchByEntryGlobalName) { | ||
| remoteInsIndex = instances.findIndex( | ||
| (ins) => ins.name === entryGlobalName, | ||
| ); | ||
| } | ||
| if (remoteInsIndex !== -1) { | ||
| const remoteIns = | ||
| CurrentGlobal.__FEDERATION__.__INSTANCES__[remoteInsIndex]; | ||
| const remoteIns = instances[remoteInsIndex]; | ||
| remoteInsId = remoteIns.options.id || remoteInsId; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this fallback successfully finds an aliased remote, its shared entries are registered with Useful? React with 👍 / 👎. |
||
| const globalShareScopeMap = getGlobalShareScope(); | ||
|
|
||
|
|
@@ -834,7 +846,16 @@ export class RemoteHandler { | |
| ]; | ||
| }, | ||
| ); | ||
| CurrentGlobal.__FEDERATION__.__INSTANCES__.splice(remoteInsIndex, 1); | ||
| instances.splice(remoteInsIndex, 1); | ||
| } else { | ||
| // Containers built without the federation runtime legitimately have | ||
| // no instance, so only warn: a stale instance would otherwise stay | ||
| // in __INSTANCES__ and leak once the remote is loaded again. | ||
| logger.warn( | ||
| `No runtime instance named "${remoteInfo.name}"${ | ||
| canMatchByEntryGlobalName ? ` (or "${entryGlobalName}")` : '' | ||
| } was found in __FEDERATION__.__INSTANCES__ while removing remote "${remote.name}", so its share scope and instance could not be released. Make sure the registered remote name matches the name the remote was built with.`, | ||
| ); | ||
| } | ||
|
|
||
| host.moduleCache.delete(remote.name); | ||
|
|
||
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.
When an aliased remote uses a custom
library.name,entryGlobalNameis that library global rather than the Module Federation build name used by the runtime instance; this lookup therefore misses the intended instance and can splice an unrelated instance whose name happens to equal the library global. It also ignoresbuildVersion, so multiple stale builds with the same name can cause the first, wrong version to be removed. Match the instance using the remote's actual build name and versioned ID instead of treatingentryGlobalNameas an instance identity.Useful? React with 👍 / 👎.