Skip to content

fix(enhanced): make the generated runtime entry deterministic and valid - #5123

Merged
ScriptedAlchemy merged 4 commits into
mainfrom
fix/enhanced-runtime-entry-deterministic
Oct 9, 2026
Merged

ScriptedAlchemy merged 4 commits into
mainfrom
fix/enhanced-runtime-entry-deterministic

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Description

FederationRuntimePlugin uses a timestamp for unnamed containers, inserts paths into unescaped string literals, and resolves relative runtime plugins from the working directory. This changes generated entries between builds and breaks quoted paths or configs run from another directory.

Use a hash of compiler name and context for the fallback name, escape import specifiers with JSON.stringify, and resolve plugins from the compiler context. Preserve the working-directory fallback with a warning. The name is stable within a checkout; it still depends on the absolute context.

Validation previously recorded: 19 focused tests, the fallback config case, a build under a quoted path, and enhanced tests pass. Windows quoted paths and #4954's package-name integration were not tested. Reported CI passes; Metro and tree-shaking E2E are skipped.

Related Issue

Related PR: #4954 changes the same plugin-resolution code. Reconcile both paths using compiler.context when merging.

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 Sep 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dc6b00b

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/enhanced Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js Patch
@module-federation/nextjs-mf Patch
@module-federation/node 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
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch
@module-federation/playground Patch
remote5 Patch
remote6 Patch
website-new Patch
@module-federation/devtools Patch
@module-federation/cli Patch
create-module-federation Patch
@module-federation/dts-plugin Patch
@module-federation/error-codes Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/metro Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
@module-federation/retry-plugin Patch
@module-federation/rspack Patch
@module-federation/runtime-core Patch
@module-federation/runtime-tools Patch
@module-federation/runtime Patch
@module-federation/sdk Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/treeshake-frontend Patch
@module-federation/treeshake-server Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/bridge-react Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-vue3 Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/esbuild Patch
@module-federation/observability-plugin 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 25, 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-25T00:53:40.126687Z 5987217 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.

@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: 5987217d21

ℹ️ 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/enhanced/src/lib/container/runtime/FederationRuntimePlugin.ts Outdated
@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

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

@module-federation/cli

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

create-module-federation

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

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/metro-plugin-rock

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/observability-plugin

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

@module-federation/playground

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/rstest

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: dc6b00b

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Report

6 package(s) changed, 37 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/enhanced 818.9 kB +1.2 kB (+0.1%) 672 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB no change 2.4 kB -33 B (-1.3%)
@module-federation/core 1.0 kB -4 B (-0.4%) 1.0 kB -34 B (-3.1%)
@module-federation/devtools 30.3 kB no change 30.3 kB -25 B (-0.1%)
@module-federation/enhanced 2.7 kB +2 B (+0.1%) 2.8 kB -45 B (-1.6%)
@module-federation/metro-plugin-rnc-cli 416 B no change 435 B -27 B (-5.8%)
@module-federation/node 9.1 kB +3 B (+0.0%) 9.2 kB -29 B (-0.3%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 22.3 kB -20 B (-0.1%) 23.8 kB -19 B (-0.1%) +1.6 kB +1 B

Total dist (raw): 23.41 MB (+1.2 kB (+0.0%))
Total ESM gzip: 111.7 kB (no change)
Total web bundle (gzip): 253.4 kB (+1 B (+0.0%))
Total node bundle (gzip): 255.6 kB (-193 B (-0.1%))
Tracked ./bundler entry gzip: 563 B (no change)
Tracked ./bundler web bundle (gzip): 4.9 kB (no change)
Tracked ./bundler node bundle (gzip): 4.9 kB (no change)

Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as ./bundler are measured separately so ENV_TARGET-driven tree-shaking is visible. Bare imports are externalized to keep package-level sizes consistent, and assets are emitted as resources.

…erals, and a stable name

Three assertions on FederationRuntimePlugin.getTemplate and the fallback
container name. Each fails on main: a relative runtimePlugins entry resolves
against process.cwd() instead of compiler.context, a path that contains a
quote makes webpack's parser reject the entry, and the fallback name changes
with the clock between two builds.
The fallback container name was container_${Date.now()}. It fed both the
runtime init options and the temp entry hash, so two identical builds
without output.uniqueName produced different contenthashes and a new
node_modules/.federation entry each build. The clock was there to keep
runtime instances apart when two builds share a page; a short hash of
compiler.context keeps them apart just as well and is the same on every
build of the same project.

getTemplate pasted the bundler runtime path and every runtimePlugins path
inside single quotes, so a path that contains a quote produced an entry
webpack's parser rejects. Emit them with JSON.stringify like every other
webpack template.

Relative runtimePlugins entries resolved against process.cwd() although the
compiler is in scope. Resolve them against compiler.context like every
other relative path webpack accepts.
…ive runtime plugins loading

The fallback name now hashes compiler.options.name with compiler.context,
so two compilers of one config that share a context get different names.
compiler.name is not used because webpack only sets it inside a
MultiCompiler. A build that uses the fallback gets a warning that asks for
output.uniqueName or a plugin name.

A relative runtimePlugins path that does not exist under compiler.context
but does exist under process.cwd() still loads from cwd, with a warning
that asks to update the path. This keeps context: __dirname with a
cwd-relative entry working when the build runs from another directory.

The unit test parses nothing: it asserts the JSON.stringify form of each
import specifier instead of calling webpack's private JavascriptParser._parse.
The warning fired in 21 sharing config cases and 2 container cases, every
standalone ContainerReferencePlugin or SharePlugin build in the suite, so it
marks a normal setup rather than a misconfiguration. webpack itself does not
warn on an empty uniqueName. The stable fallback name and the cwd-fallback
warning for runtimePlugins stay.
@ScriptedAlchemy
ScriptedAlchemy merged commit fdaeb75 into main Oct 9, 2026
24 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the fix/enhanced-runtime-entry-deterministic branch October 9, 2026 03:10
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.

2 participants