Skip to content

feat(mf): add layer-aware shared module core - #12977

Open
ScriptedAlchemy wants to merge 55 commits into
mainfrom
feat/mf-layers
Open

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

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add layer-aware shared module matching to Module Federation 1.5 (RFC #15576).

  • Match consumers by request and issuer layer; keep the shared key separate from the fallback import.
  • Relative shared requests and fallback imports keep resolving against the compiler context, as in webpack. Only a consume with issuerLayer is matched and resolved from its issuer, matching the enhanced webpack plugin. Layer names must be non-empty strings.
  • Preserve scope, layer, version, and import identity through provider resolution, tree-shaking, and independent fallback builds.
  • Prefer matching layers over unlayered fallback configurations while retaining legacy unlayered behavior.

Rust SharedIdentity values are cloned because the same owned scope/key/layer identity keys separate matching, provider, and export-usage maps. RequestMatchKey clones copy request/layer strings when the export optimizer builds its prefix lookup map.

Coverage

Config cases cover layered matching, aliases, prefix requests, fallback imports, identifier collisions, and export usage. Public API and type tests cover enhanced-option validation.

Related links

Stack 1/4: #12977 → #14911 → #14912 → #14913.

Checklist

  • Tests updated.
  • Documentation updated.

@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, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 529.6 KB 0 0
react-10k 5.4 MB 1.3 MB 0 0
react-1k 827.7 KB 226.6 KB 0 0
react-5k 2.6 MB 670.9 KB 0 0
ui-components 4.7 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@github-actions

github-actions Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 06742b2 to perf(sources): compact retained source storage (#15944) by Cong-Cong Pan

❌ Size increased by 36.00KB from 69.42MB to 69.46MB (⬆️0.05%)

@codspeed

codspeed Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 54 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing feat/mf-layers (06742b2) with main (81eca8e)

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
@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: 06742b2
Status: ✅  Deploy successful!
Preview URL: https://c232bd4d.rspack-v2.pages.dev
Branch Preview URL: https://feat-mf-layers.rspack-v2.pages.dev

View logs

Comment thread crates/rspack_plugin_mf/src/sharing/collect_shared_entry_plugin.rs Outdated
Comment thread crates/rspack_plugin_mf/src/manifest/utils.rs
Comment thread packages/rspack-test-tools/src/case/watch.ts Outdated
Comment thread crates/rspack_plugin_mf/src/sharing/shared_used_exports_optimizer_plugin.rs Outdated
Comment thread packages/rspack/src/runtime/moduleFederationDefaultRuntime.js
Comment thread packages/rspack/src/sharing/SharePlugin.ts Outdated
Comment thread crates/rspack_core/src/stats/mod.rs
Comment thread crates/rspack_plugin_mf/src/container/container_entry_module.rs Outdated
let share_init_items = scopes
.iter()
.map(|scope| ShareInitData {
share_scope: ShareScope::Single(scope.clone()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not pass through the scopes and change to Single here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also need @2heal1 to review share_scope related changes, I see lots of similar changes like this, not sure whether it's expected

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The remote now passes the scopes through with share_scope: self.share_scope.clone():

codegen.data_mut().insert(CodeGenerationDataShareInit {
items: vec![ShareInitData {
share_scope: self.share_scope.clone(),
init_stage: 20,
init: DataInitInfo::ExternalModuleId(id.cloned()),
}],

Leaving this thread open for the requested @2heal1 review of the share-scope changes.

}

if matches!(module_type, ModuleType::ConsumeShared)
&& let Some((pkg, required)) = parse_consume_shared_identifier(&identifier)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need @2heal1 to review the manifest related changes

@ScriptedAlchemy
ScriptedAlchemy changed the base branch from main to codex/mf-structural-shared-identities July 22, 2026 22:37
@ScriptedAlchemy ScriptedAlchemy changed the title feat(mf): layer-aware sharing and runtime scope-array support feat(mf): add layer-aware shared module core Jul 22, 2026
@ScriptedAlchemy
ScriptedAlchemy changed the base branch from codex/mf-structural-shared-identities to main July 22, 2026 23:05
@ScriptedAlchemy
ScriptedAlchemy force-pushed the feat/mf-layers branch 2 times, most recently from 15e299e to 3a443d9 Compare July 23, 2026 00:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 907852d953

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rspack/src/sharing/IndependentSharedPlugin.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca4e8cc35e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rspack/src/runtime/moduleFederationDefaultRuntime.js Outdated
# Conflicts:
#	crates/rspack_plugin_mf/src/container/container_entry_module.rs
#	crates/rspack_plugin_mf/src/sharing/consume_shared_module.rs
#	crates/rspack_plugin_mf/src/sharing/provide_shared_module.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b17652661c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/rspack/src/sharing/IndependentSharedPlugin.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff601a5915

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/rspack_plugin_mf/src/sharing/provide_shared_plugin.rs Outdated
Resolve two conflicts from #15674 (share BuildContext across module graph
tasks): keep the layer-aware branches and read runtime_mode from
data.build_context.compiler_options.
The ConsumeShared source is the same string as CodeGenerationDataConsumeShared::fallback,
falling back to "undefined" in both places.
Restore webpack's early return in ProvideSharedPlugin for a resource already
resolved for the same config, now keyed by (resource, layer). Validate that
shared layer and issuerLayer are non-empty strings where the options are
introduced, and document that they need the enhanced runtime.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…umes

Only a consume with issuerLayer is matched and resolved from its issuer, as the
enhanced webpack plugin does. Unlayered relative shared requests and fallback
imports resolve against the compiler context again, so the pre-existing
fallback-context case is shared instead of silently falling through, and the
request-origins fixture asserts the compiler-context fallback.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 738ce9861d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/rspack_plugin_mf/src/sharing/provide_shared_dependency.rs Outdated

This branch has not been deployed

No deployments
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