fix(runtime-core): sync shared options after dynamic registration - #4950
fix(runtime-core): sync shared options after dynamic registration#4950dmchoi77 wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 68a5ddb The changes in this PR will be included in the next version bump. This PR includes changesets to release 47 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
options.shared represents the user’s shared configuration, so registerShared() should not mutate it. Runtime-registered shares should be stored in SharedHandler’s internal state and used by loadShare() and |
|
@2heal1 Thanks for the feedback. I updated the implementation so Runtime-registered shares are now kept in I also added regression coverage for:
|
Description
Summary
ModuleFederation.registerShared()updates the runtime share scope, but does not updateinstance.options.sharedwith the newly registered shared entries.loadShare()uses the shared options frominstance.options.sharedwhen resolving a target shared module. As a result, a shared module registered through the publicregisterShared()API cannot be loaded immediately throughloadShare().This change keeps
instance.options.sharedsynchronized with the complete result returned bySharedHandler.registerShared().Problem
The current implementation calls
SharedHandler.registerShared()but discards itsallShareInfosresult:This leaves the runtime in an inconsistent state:
loadShare()then resolves against the staleoptions.sharedstate instead of the shared module that was just registered.Reproduction
After
registerShared(), the module is present inshareScopeMap, but the corresponding entry is missing frommf.options.shared.loadShare()therefore cannot resolve the dynamically registered shared module reliably.Root Cause
SharedHandler.registerShared()already returns the merged shared information asallShareInfos. The initial options formatting path stores this result inoptions.shared, but the public dynamic registration path does not.The two paths should maintain the same invariant:
Related Issue
fixes #4952
Types of changes
Checklist