Skip to content

fix(mf-runtime): await remote initialization before loading exposed modules - #1126

Open
Moulyy wants to merge 1 commit into
angular-architects:mainfrom
Moulyy:fix/mf-runtime-await-remote-init
Open

fix(mf-runtime): await remote initialization before loading exposed modules#1126
Moulyy wants to merge 1 commit into
angular-architects:mainfrom
Moulyy:fix/mf-runtime-await-remote-init

Conversation

@Moulyy

@Moulyy Moulyy commented Sep 3, 2026

Copy link
Copy Markdown

Problem

When loading an ESM remote, loadRemoteModuleEntry() starts the remote initialization without awaiting it:

initRemote(container, remoteEntry);
containerMap[remoteEntry] = container;

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 before initRemote() has completed. This allows lookupExposedModule() and container.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:

await initRemote(container, remoteEntry);
containerMap[remoteEntry] = container;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant