Skip to content

PoC: resolve a promise once all remote bundles are initialized - #59

Draft
petschki wants to merge 1 commit into
mainfrom
mf-await-remote-initialization
Draft

PoC: resolve a promise once all remote bundles are initialized#59
petschki wants to merge 1 commit into
mainfrom
mf-await-remote-initialization

Conversation

@petschki

Copy link
Copy Markdown
Member

The document-ready handler started the initialization of all Module Federation remote bundles but did not wait for them: the patternslib__mf--loaded event fired before any remote had actually loaded and run its main module. Consumers had no way to know when the remotes' patterns and components were registered.

The helper now initializes all remotes in parallel, waits for all of them to settle (a failing remote is logged and does not block the others), and only then dispatches the event. The new promise window.__patternslib_mf_initialized is created at module load time, so it can be awaited by code running before or after document ready — the Patternslib registry uses it to defer the initial DOM scan.

A remote's main module usually only does import("./bundle") — the async boundary needed to consume shared modules — and the registrations happen in that chunk. If the main module exports that promise as its default export (export default import("./bundle")), the helper waits for it as well. Remotes without the export keep working as before.

see also Patternslib/Patterns#1291

…e initialized

The document-ready handler started the initialization of all Module
Federation remote bundles but did not wait for them: the
``patternslib__mf--loaded`` event fired before any remote had actually
loaded and run its main module. Consumers had no way to know when the
remotes' patterns and components were registered.

The helper now initializes all remotes in parallel, waits for all of
them to settle (a failing remote is logged and does not block the
others), and only then dispatches the event. The new promise
``window.__patternslib_mf_initialized`` is created at module load time,
so it can be awaited by code running before or after document ready —
the Patternslib registry uses it to defer the initial DOM scan.

A remote's main module usually only does ``import("./bundle")`` — the
async boundary needed to consume shared modules — and the registrations
happen in that chunk. If the main module exports that promise as its
default export (``export default import("./bundle")``), the helper
waits for it as well. Remotes without the export keep working as
before.
@petschki
petschki requested a review from thet September 10, 2026 12:03
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