Skip to content

feat(mf): shareScope support array type#13107

Merged
ahabhgk merged 16 commits intomainfrom
feat/mf-share-array-scope
Mar 6, 2026
Merged

feat(mf): shareScope support array type#13107
ahabhgk merged 16 commits intomainfrom
feat/mf-share-array-scope

Conversation

@2heal1
Copy link
Copy Markdown
Member

@2heal1 2heal1 commented Feb 24, 2026

Summary

Support array shareScope to satisfy multiple shareScope demands, like rsc or other advanced features.

Related doc: https://module-federation.io/guide/advanced/multiple-shared-scope.html

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings February 24, 2026 08:11
@2heal1 2heal1 requested a review from hardfist as a code owner February 24, 2026 08:11
@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Feb 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Module Federation/share configuration to accept shareScope as either a string or an array of strings (normalized to a single scope internally), and adds a new rspack-test config case to validate the behavior.

Changes:

  • Add ShareScope = string | string[] and propagate it through MF/sharing plugin option types.
  • Normalize array-form shareScope values in JS/TS and in the Rust binding layer.
  • Add a new remote-array-share-scope configCase with host/remote setup to exercise array-form shareScope.

Reviewed changes

Copilot reviewed 15 out of 22 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/test.config.js Test harness config for selecting the output bundle.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/runtime-plugin.js Runtime plugin used by the test to proxy remote entry loading locally.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/rspack.config.js MF configuration for host + provider, including array-form shareScope.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib/package.json Fixture package for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib/index.js Fixture implementation for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib2/package.json Fixture package for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib2/index.js Fixture implementation for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib3/package.json Fixture package for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/node_modules/@scope-sc/ui-lib3/index.js Fixture implementation for shared module in the test case.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js Test assertions validating sharing behavior under the new config shape.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/Expose.js Remote-exposed module used by the test to validate shared instances.
tests/rspack-test/configCases/container-1-5/remote-array-share-scope/App.js Host-side module that mutates shared module state to validate sharing.
packages/rspack/src/sharing/SharePlugin.ts Introduces ShareScope union type and a helper to normalize it.
packages/rspack/src/sharing/ProvideSharedPlugin.ts Updates provide-side option types to accept ShareScope.
packages/rspack/src/sharing/ConsumeSharedPlugin.ts Updates consume-side option types to accept `string
packages/rspack/src/sharing/CollectSharedEntryPlugin.ts Updates option types to accept ShareScope.
packages/rspack/src/container/ModuleFederationPluginV1.ts Updates MF v1 option typing to accept ShareScope.
packages/rspack/src/container/ModuleFederationPlugin.ts Normalizes array-form shareScope when building runtime remoteInfos.
packages/rspack/src/container/ContainerReferencePlugin.ts Updates reference plugin option typing to accept ShareScope.
packages/rspack/src/container/ContainerPlugin.ts Updates container plugin option typing to accept ShareScope.
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_mf.rs Accepts share_scope as Either<String, Vec<String>> and normalizes to a single string.
crates/node_binding/napi-binding.d.ts Updates TS binding surface to use RawShareScope for relevant fields.
Comments suppressed due to low confidence (4)

tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js:4

  • The test name references tree-shaking/runtime-infer, but this case is about shareScope accepting an array. Updating the it(...) description will make failures easier to diagnose and keep the suite searchable.
it('should load tree shaking shared via set "runtime-infer" mode', async () => {
  const App = await import('./App.js');

tests/rspack-test/configCases/container-1-5/remote-array-share-scope/index.js:11

  • This comment says UiLib3 should not be shared, but the expectations below assert 0.1.5 (which would only happen if the remote sees the host-mutated version). Please update or remove the comment to match the actual intended behavior.
  // TheUiLib3 should not shared
  expect(Expose.default()).toBe(`UiLib1: This is @scope-sc/ui-lib 0.1.3

tests/rspack-test/configCases/container-1-5/remote-array-share-scope/rspack.config.js:10

  • output is declared twice; the later output object overwrites the earlier one, so ignoreBrowserWarnings: true is currently a no-op. Merge these into a single output block so all settings apply.
	entry: './index.js',
	output: {
		ignoreBrowserWarnings: true
	},

tests/rspack-test/configCases/container-1-5/remote-array-share-scope/runtime-plugin.js:13

  • entry.replace(...) will throw if remoteInfo.entry is undefined (e.g. non-script externals). Consider guarding on entry being a string and matching the expected prefix before doing the replacement/require, similar to other test runtime-plugins in this repo.
    loadEntry: ({ remoteInfo }) => {
      const { entry, entryGlobalName } = remoteInfo;
      const relativePath = entry.replace('http://localhost:3001/', './');
      globalThis[entryGlobalName] =
          __non_webpack_require__(relativePath)[entryGlobalName];
        return globalThis[entryGlobalName];

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 24, 2026

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.2 KB 0
ui-components 2.3 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 24, 2026

📦 Binary Size-limit

Comparing 04624f5 to perf: improve find_new_name (#13209) by harpsealjs

❌ Size increased by 14.00KB from 48.99MB to 49.00MB (⬆️0.03%)

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 24, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing feat/mf-share-array-scope (04624f5) with main (0c27b95)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Feb 25, 2026

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: df2829a
Status: ✅  Deploy successful!
Preview URL: https://8b8379ef.rspack-v2.pages.dev
Branch Preview URL: https://feat-mf-share-array-scope.rspack-v2.pages.dev

View logs

@2heal1 2heal1 force-pushed the feat/mf-share-array-scope branch from df2829a to 5ea29e6 Compare March 5, 2026 10:53
@ahabhgk ahabhgk enabled auto-merge (squash) March 6, 2026 08:16
@ahabhgk ahabhgk merged commit 81ba178 into main Mar 6, 2026
49 checks passed
@ahabhgk ahabhgk deleted the feat/mf-share-array-scope branch March 6, 2026 08:33
@2heal1 2heal1 mentioned this pull request Mar 9, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants