Skip to content

fix(runtime): select the tree-shaking share plugin and test bundle contents - #5107

Open
ScriptedAlchemy wants to merge 19 commits into
rfc5036/06-docs-rolloutfrom
rfc5036/07-handler-contracts
Open

ScriptedAlchemy wants to merge 19 commits into
rfc5036/06-docs-rolloutfrom
rfc5036/07-handler-contracts

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Part of RFC #5036. An alternate proposal is open at #5128 with its own stack. This PR stays open until the decision on #5036 is made.
Stack: 7 of 7. Base: #5098 (rfc5036/06-docs-rollout). Next: none.
Landing order: #5093 → #5094 → #5095 → #5096 → #5097 → #5098 → #5107.

What changes

A module-federation:no-shared build now leaves out the tree-shaking share plugin, which used to bypass the package selectors. Default builds behave as on main. The selector tests now check what a caller or a bundle sees instead of internal dist file names.

The plugin moves behind #mf/tree-shaking-share-plugin. It still patches treeShaking.status from the host snapshot when bundlerRuntime is missing, as on main, and only skips wrapping shared getters in that case. getRemoteInfo and getRemoteEntryUniqueKey move to utils/remoteInfo.ts.

The public getRemoteEntry behavior is unchanged. It is not gated by FEDERATION_OPTIMIZE_NO_REMOTE or by a package condition, because webpack-bundler-runtime loads local tree-shaken shared fallbacks through it even when a host has no remotes. Remote loading stays gated through the #mf/remote-module and #mf/remote-handler selectors.

The disabled handler changes that were here earlier now live in #5095, so that PR works on its own. This PR does not make the compiler pass module-federation:* conditions.

Verification

  • The branch history was rewritten on 2026-09-26 to remove attribution trailers from commit messages only. Every tree and patch is identical to the verified head; c813c4fdd is the rewritten tip.

  • The module-federation:no-remote Webpack and Rspack bundles do not contain the remote module class marker, and the default bundles do.

  • The module-federation:target-web SDK bundles do not contain the Node loader marker, and the default bundles do.

  • The disabled container entry module has no initContainerEntry export.

  • The tree-shaking share plugin patches treeShaking.status without a bundler runtime and is left out under module-federation:no-shared.

  • Locally, the runtime-core selector, handler, worker, image, and load suites passed 40 tests, the SDK selector suite 11, and the bundler-runtime selector suite 6. The webpack-bundler-runtime and bridge-react typechecks pass. The runtime-core typecheck passes apart from two existing errors in utils/preload.ts.

  • CI at c813c4fdd passed 20 checks, cancelled 2, and skipped 1. Lint Dependencies and pkg.pr.new Preview each ran twice on this commit. They set cancel-in-progress: true per PR, so the second run cancelled the first about a second after it started. The second runs passed, and the cancelled runs were not rerun.

  • e2e-treeshake was skipped because tools/scripts/ci-is-affected.mjs did not select it. It has not run since feat(managers): resolve runtime families atomically #5093's head, so no end-to-end run covers the moved tree-shaking share plugin. The other end-to-end suites passed at this head, which builds the whole stack.

Deviations from the RFC

None noted.

Overlaps with open PRs

File overlaps with 8 other open PRs

Disabled handlers now expose the members callers use, so runtime-core
typechecks without treating them as the enabled classes. Remote entry
loading and the tree-shaking share plugin follow the same selectors and
optimization defines as the other runtime modules.
@changeset-bot

changeset-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c813c4f

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

This PR includes changesets to release 48 packages
Name Type
@module-federation/runtime-core Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/nextjs-mf Patch
@module-federation/runtime Patch
@module-federation/bridge-react Patch
@module-federation/enhanced Patch
@module-federation/esbuild Patch
@module-federation/runtime-tools Patch
@module-federation/devtools Patch
@module-federation/dts-plugin 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/bridge-vue3 Patch
website-new Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rspress-plugin Patch
@module-federation/rstest Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/rspack Patch
@module-federation/inject-external-runtime-core-plugin 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
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
remote5 Patch
remote6 Patch
@module-federation/cli Patch
create-module-federation Patch
@module-federation/error-codes Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/sdk Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/treeshake-frontend Patch
@module-federation/treeshake-server Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/bridge-shared 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-21T05:10:09.797111Z 41fcea8 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

The disabled handler types were missing idToRemoteMap and
getGlobalRemoteInfo, so the bridge-react build failed on the union.
@pkg-pr-new

pkg-pr-new Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@c813c4f

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@c813c4f

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@c813c4f

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@c813c4f

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@c813c4f

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@c813c4f

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@c813c4f

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@c813c4f

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@c813c4f

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@c813c4f

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@c813c4f

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@c813c4f

@module-federation/metro-plugin-rock

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rock@c813c4f

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@c813c4f

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@c813c4f

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@c813c4f

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@c813c4f

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@c813c4f

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@c813c4f

@module-federation/observability-plugin

pnpm add https://pkg.pr.new/@module-federation/observability-plugin@c813c4f

@module-federation/playground

pnpm add https://pkg.pr.new/@module-federation/playground@c813c4f

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@c813c4f

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@c813c4f

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@c813c4f

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@c813c4f

@module-federation/rstest

pnpm add https://pkg.pr.new/@module-federation/rstest@c813c4f

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@c813c4f

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@c813c4f

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@c813c4f

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@c813c4f

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@c813c4f

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@c813c4f

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@c813c4f

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@c813c4f

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@c813c4f

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@c813c4f

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@c813c4f

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@c813c4f

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@c813c4f

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@c813c4f

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@c813c4f

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@c813c4f

commit: c813c4f

The Webpack compile in the platform loader selector test exceeded Jest's
5 second limit on CI and was killed before it finished.
The selector checks now run the public function and the bundled
program. They no longer pass by matching internal dist paths.
The selector checks only need the program result. Production minification
did not finish before the test runner reached its limit, so the assertion
never ran.
…nged

The public getRemoteEntry export was gated by the #mf/remote-entry selector.
webpack-bundler-runtime loads local tree-shaken shared fallbacks through it,
so disableRemote broke shared loading for hosts with no remotes. The export
now comes from utils/load again and the selector is deleted. Remote loading
stays gated by the remote-module and remote-handler selectors.

ModuleFederation typed its handler fields as the union of the enabled and
disabled classes, which broke external access to enabled-only members. The
fields keep the enabled class types and the constructor narrows once.

DisabledSnapshotHandler rejects instead of throwing from a Promise-returning
method and types manifestCache as Map<string, Manifest>.

Tests cover the public loader under the no-remote condition with the define
set, and the define picking the disabled or enabled remote handler.
…dler runtime

The selector version of the tree-shaking share plugin returned early when
bundlerRuntime was missing, which skipped the snapshot status patching that
main performs without it. Only the shared getter wrapping needs
bundlerRuntime, so the guard moves there.

The container entry test asserts the disabled leaf has no export instead of
matching a V8 error string, and the plugin test now reaches the bundler
runtime guard with a shared fallback and a host snapshot present.
The webpack and Rspack bundle tests read the output bundle and assert that a
marker string from the excluded module is absent, with the default bundle as
the control: the remote module class under module-federation:no-remote and
the Node script loader under module-federation:target-web.
# Conflicts:
#	packages/runtime-core/__tests__/remote-module-selector.spec.ts
#	packages/runtime-core/src/utils/load.ts
#	packages/sdk/__tests__/platform-loader-selector.spec.ts
#	packages/webpack-bundler-runtime/__tests__/container-entry-selector.spec.ts
@ScriptedAlchemy ScriptedAlchemy changed the title fix(runtime): type disabled handlers and select remote entry fix(runtime): select the tree-shaking share plugin and test bundle contents Sep 24, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant