Skip to content

Commit

Permalink
fix(module-federation): use 'hoisted' runtime for node to prevent iss…
Browse files Browse the repository at this point in the history
…ues with eager sharing (#29104)

## Current Behavior
SSR with Module Federation frequently encounters issues related to the
eager resolution of shared packages.
This has resulted in numerous erroneous behaviours including but not
limited to:
- Failure to start server
- Failure to resolve remotes
- Failure to server render remotes

## Expected Behavior
Using the `'hoisted'` runtime provided by MF 2.0, we can ensure that SSR
for Module Federation runs in an async environment, removing the issues
surrounding eager consumption and resolution of shared modules.
In testing, this has fixed the issues outlined above

## Related Issue(s)

Fixes #27000
Fixes #27964
  • Loading branch information
Coly010 authored Nov 28, 2024
1 parent 8eb6159 commit 182b46c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ export async function withModuleFederationForSSR(
shared: {
...sharedDependencies,
},
remoteType: 'script',
library: {
type: 'commonjs-module',
},
/**
* Apply user-defined config override
*/
...(configOverride ? configOverride : {}),
experiments: {
federationRuntime: 'hoisted',
// We should allow users to override federationRuntime
...(configOverride?.experiments ?? {}),
},
runtimePlugins:
process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export async function withModuleFederationForSSR(
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
experiments: {
federationRuntime: 'hoisted',
// We should allow users to override federationRuntime
...(configOverride?.experiments ?? {}),
},
runtimePlugins:
process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,19 @@ export async function withModuleFederationForSSR(
shared: {
...sharedDependencies,
},
remoteType: 'script',
library: {
type: 'commonjs-module',
},
/**
* Apply user-defined config overrides
*/
...(configOverride ? configOverride : {}),
experiments: {
federationRuntime: 'hoisted',
// We should allow users to override federationRuntime
...(configOverride?.experiments ?? {}),
},
runtimePlugins:
process.env.NX_MF_DEV_REMOTES &&
!options.disableNxRuntimeLibraryControlPlugin
Expand Down

0 comments on commit 182b46c

Please sign in to comment.