Skip to content

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

Merged
Aukevanoost merged 2 commits into
angular-architects:mainfrom
Moulyy:fix/mf-runtime-await-remote-init
Sep 11, 2026
Merged

Aukevanoost merged 2 commits into
angular-architects:mainfrom
Moulyy:fix/mf-runtime-await-remote-init

Conversation

@Moulyy

@Moulyy Moulyy commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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.

Comment thread libs/mf-runtime/src/lib/loader/dynamic-federation.ts Outdated
Co-authored-by: Nikita Karamov <me@kytta.dev>
@Aukevanoost
Aukevanoost merged commit 198294c into angular-architects:main Sep 11, 2026
1 check passed
Aukevanoost added a commit that referenced this pull request Sep 11, 2026
fix(mf-runtime): await remote initialization before loading exposed modules
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.

3 participants