Skip to content

fix(runtime): propagate share scopes to nested remotes - #4913

Open
dmchoi77 wants to merge 1 commit into
module-federation:mainfrom
dmchoi77:fix/nested-remote-share-scope-propagation
Open

fix(runtime): propagate share scopes to nested remotes#4913
dmchoi77 wants to merge 1 commit into
module-federation:mainfrom
dmchoi77:fix/nested-remote-share-scope-propagation

Conversation

@dmchoi77

Copy link
Copy Markdown
Contributor

Description

Propagate the complete host share scope map when initializing a remote container.

Previously, only the share scope selected for the current remote was added to the remote container's runtime state. When that remote loaded another nested remote using a different share scope, the nested remote could not access shared dependencies from the upstream host. This could cause singleton dependencies such as React to be loaded more than once.

This change:

  • Copies the inherited host share scope map into the remote container while preserving the explicitly initialized scope.
  • Allows nested remotes to reuse shared dependencies already provided by the upstream host.
  • Adds a regression test covering the Host A → Remote B → Remote C initialization path with separate React 18 and React 19 share scopes.
  • Adds a patch changeset for @module-federation/runtime-core.

Validation

  • pnpm --filter @module-federation/runtime-core test -- instance.spec.ts
    • Passed all 93 tests across 12 runtime-core test files.
  • pnpm --filter @module-federation/runtime-core lint
    • Passed.
  • pnpm --filter @module-federation/runtime-core build
    • Passed.
  • pnpm exec prettier --check packages/runtime-core/__tests__/instance.spec.ts packages/runtime-core/src/shared/index.ts .changeset/fix-nested-remote-share-scopes.md
    • Passed.
  • Confirmed that the regression test fails when the share scope map propagation is removed and passes with the fix applied.
  • Manually verified the original reproduction: the nested React component renders successfully without loading a duplicate React instance.

Related Issue

Fixes #4723

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 20dfdaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 47 packages
Name Type
@module-federation/runtime-core Patch
@module-federation/nextjs-mf Patch
@module-federation/runtime Patch
@module-federation/bridge-react Patch
@module-federation/devtools Patch
@module-federation/dts-plugin Patch
@module-federation/esbuild Patch
@module-federation/metro Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/node Patch
@module-federation/observability-plugin Patch
@module-federation/playground Patch
@module-federation/retry-plugin Patch
@module-federation/runtime-tools Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/bridge-vue3 Patch
website-new Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
@module-federation/rsbuild-plugin Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
@module-federation/enhanced Patch
@module-federation/rspack Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/rspress-plugin Patch
remote5 Patch
remote6 Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/sdk Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/error-codes Patch
create-module-federation Patch
@module-federation/cli Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend Patch
@module-federation/utilities Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Share scope not shared globally when different share scope in-between

1 participant