fix(mf-runtime): await remote initialization before loading exposed modules - #1126
Open
Moulyy wants to merge 1 commit into
Open
fix(mf-runtime): await remote initialization before loading exposed modules#1126Moulyy wants to merge 1 commit into
Moulyy wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When loading an ESM remote,
loadRemoteModuleEntry()starts the remote initialization without awaiting it:As a result,
loadRemoteModule()can continue with container.get() before container.init() has completed.This creates a race condition when the remote uses shared modules. In our case, the Vue/Vite remote shares Pinia. The exposed module can be evaluated while Pinia is still being initialized, causing the generated shared-module binding to be used before it is assigned:
TypeError: __mf_3 is not a function
The issue is intermittent and occurs mainly after repeated browser reloads. All related network requests return HTTP 200, so the failure happens during module initialization/execution rather than during resource loading.
Cause
loadRemoteModuleEntry()resolves beforeinitRemote()has completed. This allowslookupExposedModule()andcontainer.get()to run before the remote share scope is ready.Changes
The remote initialization is now awaited before storing the container and resolving the entry-loading promise:
The script-based loading path is also updated to wait for initialization before calling
resolve().Expected result
loadRemoteModule()only loads the exposed module after the remote container and its shared dependencies have been initialized. This prevents exposed modules from being evaluated before shared dependencies such as Pinia are ready.