Skip to content

feat(mf): layer-aware sharing and runtime scope-array support#12977

Draft
ScriptedAlchemy wants to merge 90 commits into
mainfrom
feat/mf-layers
Draft

feat(mf): layer-aware sharing and runtime scope-array support#12977
ScriptedAlchemy wants to merge 90 commits into
mainfrom
feat/mf-layers

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add layer support for Module Federation shared modules across provide and consume flows
  • Add layer metadata support for exposed modules so expose entries can participate in layered builds
  • Keep the runtime aligned with Module Federation core, only adding the minimal layer-specific glue needed for layered sharing
  • Align the Rspack layer test cases with the Module Federation core layer fixtures

What This Changes

  • Thread layer / issuerLayer metadata through shared module configuration and runtime registration
  • Preserve layer information in federation manifest and shared-entry generation paths
  • Support layered exposed modules in the enhanced Module Federation path
  • Validate the behavior with the container-1-5 layer serial cases and the matching sharing/tree-shaking cases

Why This PR Exists

Rspack already supports share scopes as arrays from earlier work. This PR is not re-adding generic array share-scope support.

The purpose of this PR is to add layer-aware federation behavior so layered shared modules and layered exposed modules work the same way as they do in Module Federation core.

Stack

Current stack, bottom to top:

  • #12977 feat(mf): layer-aware sharing and runtime scope-array support <- this PR
  • #13203 feat(mf): emit RSC metadata in federation manifests
  • #13204 feat(rsbuild): add RSC federation host/remote example
  • #13208 feat(rsbuild): add RSC federation module patterns
  • #13215 feat(rsc): register federation manifest data at runtime

@github-actions github-actions Bot added the release: feature release: feature related release(mr only) label Feb 7, 2026
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 5 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
react-10k 5.6 MB 1.3 MB - -
popular-libs 1.7 MB 551.8 KB - -
react-5k 2.7 MB 663.8 KB - -
react-1k 823.1 KB 217.0 KB - -
ui-components 4.9 MB 1.4 MB - -
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.6 MB - -
🗜️ Gzip Size 1.3 MB - -
📄 JavaScript 5.6 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 popular-libs

Path: ../build-tools-performance/cases/popular-libs/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 1.7 MB - -
🗜️ Gzip Size 551.8 KB - -
📄 JavaScript 1.7 MB - -
🎨 CSS 0 B - -
🌐 HTML 289.0 B - -
📁 Other Assets 0 B - -

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.7 MB - -
🗜️ Gzip Size 663.8 KB - -
📄 JavaScript 2.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 823.1 KB - -
🗜️ Gzip Size 217.0 KB - -
📄 JavaScript 822.7 KB - -
🎨 CSS 0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 4.9 MB - -
🗜️ Gzip Size 1.4 MB - -
📄 JavaScript 4.8 MB - -
🎨 CSS 112.1 KB - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

Generated by Rsdoctor GitHub Action

@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 6475db9 to fix(rsc): preserve multiple referenced client exports (#14794) by Cong-Cong Pan

❌ Size increased by 200.00KB from 66.55MB to 66.75MB (⬆️0.29%)

@codspeed-hq

codspeed-hq Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 43 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing feat/mf-layers (6475db9) with main (786dec5)

Open in CodSpeed

Footnotes

  1. 47 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.

@ScriptedAlchemy ScriptedAlchemy changed the title feat/mf layers feat(mf): layer-aware sharing and runtime scope-array support Feb 7, 2026
ScriptedAlchemy and others added 2 commits February 8, 2026 23:37
test: retry native watcher watch steps

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Feb 28, 2026

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 96618cb
Status: ✅  Deploy successful!
Preview URL: https://010f4784.rspack-v2.pages.dev
Branch Preview URL: https://feat-mf-layers.rspack-v2.pages.dev

View logs

Hydrate consume handler mappings from consumes loading data so bundler-runtime keeps layer-aware share metadata in the enhanced path. Also validate multi-entry share scopes unless enhanced mode is enabled, and emit remote external metadata alongside remote runtime records.
Keep provide shared runtime entries in their original shareScope shape and mark enhanced initializeSharingData as already updated so bundler-runtime does not rebuild downgraded shared registrations from the legacy structure.
Emit consume-shared source data for shared consumers and let the runtime module reuse it when serializing consume metadata. This keeps module-output consume entries callable so layered federation consumers can initialize sharing before resolving shared react.

Made-with: Cursor
Wait for consume share scopes to finish initializing before delegating to the bundler runtime so layered shared modules resolve consistently. Remove the temporary federation debug instrumentation that was added while tracing the runtime flow.

Made-with: Cursor
Drop the temporary discovery document now that the parity investigation is captured elsewhere.

Made-with: Cursor
Reinstate legacy share-scope validation and restore the enhanced runtime metadata paths needed for layered consume and module remote resolution.

Made-with: Cursor
Preserve layer-aware shared metadata across manifest generation, used-exports optimization, and module remote runtime wiring so layered federation outputs stay correct and covered.

Made-with: Cursor
Keep layered consume scope initialization in the enhanced runtime while preserving legacy consume version-check behavior and rust lint parity.

Made-with: Cursor
# Conflicts:
#	crates/rspack_plugin_javascript/Cargo.toml
#	crates/rspack_plugin_mf/src/container/remote_runtime_module.rs
#	crates/rspack_plugin_mf/src/manifest/mod.rs
#	crates/rspack_plugin_mf/src/manifest/utils.rs
#	crates/rspack_plugin_mf/src/sharing/collect_shared_entry_plugin.rs
#	crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs
#	crates/rspack_plugin_mf/src/sharing/consume_shared_plugin.rs
#	crates/rspack_plugin_mf/src/sharing/mod.rs
#	crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs
#	crates/rspack_plugin_mf/src/sharing/provide_shared_plugin.rs
#	crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_runtime_module.rs
#	packages/rspack/src/runtime/moduleFederationDefaultRuntime.js
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.

2 participants