RFC: Layer-aware Module Federation #15576
ScriptedAlchemy
started this conversation in
RFC
Replies: 1 comment
|
@2heal1 could you take a look at this layer-aware Module Federation proposal and share your thoughts? In particular, I would appreciate your input on the exposed/shared layer options and keeping the Rspack and enhanced Webpack implementations aligned. The companion core implementation is in module-federation/core#5039. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RFC: Layer-aware Module Federation
Summary
Make Module Federation 1.5 respect Rspack layers when sharing dependencies, exposing modules, and generating manifests. A shared package can have separate server and client variants without giving each variant an unrelated shared key.
Motivation
Layers already distinguish module builds, but federation must carry that distinction through resolution, runtime initialization, tree-shaking, and metadata. Losing it can select the wrong implementation or attribute exports and assets to the wrong variant.
ReactLynx use case
ReactLynx compiles the same component source differently for background and main-thread execution:
Federation must preserve those variants throughout compilation and delivery:
exposes.layerselects each compiled variant.shared.issuerLayermatches the importing layer;shared.layerselects its provider or fallback.Realm-qualified share scopes isolate runtime negotiation, but cannot replace compile-time layer selection. Singleton identity remains local to a realm—not shared across threads.
The Lynx federation adapter demonstrates this requirement. The companion Lynx lifecycle changes support loading those bundles; they address a separate transport concern.
Proposal
shared.requestshared.shareKeyshared.issuerLayershared.layerexposes[key].layershareScope['app', 'default']in enhanced mode.For example, expose one module in two layers and share an example package separately in each:
Matching layer configurations take precedence over unlayered fallbacks. Layer names must be nonempty when supplied; omitting the layer preserves unlayered behavior.
Ordered
shareScopearrays retain their order through runtime initialization. Initial ordered consumers wait for initialization; existing scalar eager consumers remain synchronous. Scope order does not replace version or loading strategy.Manifests retain existing fields and add layer/scope identity and expose requirements. Export usage and fallback assets stay associated with the correct identity. Optional per-provider reporting is a separate proposal, not part of this layers implementation.
Compatibility and scope
Trade-offs
Using separate share keys or builds avoids this extension, but forces applications to encode layer identity themselves. Carrying it through federation keeps configuration consistent with Rspack's module graph, at the cost of more runtime/metadata bookkeeping and some binding-size growth.
Delivery and review
The implementation is one ordered stack:
Reader/types coordination: module-federation/core#5039.
Review should verify layer isolation, exact versus unlayered matching, ordered startup, provider/export attribution, and unchanged legacy behavior. Feedback requested: are the option boundaries and additive metadata sufficient for other layer-based integrations?
All reactions