Skip to content

fix(enhanced): key cache serializers by install directory - #5144

Open
ScriptedAlchemy wants to merge 2 commits into
mainfrom
fix/enhanced-duplicate-serializable
Open

ScriptedAlchemy wants to merge 2 commits into
mainfrom
fix/enhanced-duplicate-serializable

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Found while building the RFC #5128 stack; the same fix is carried in #5140.

Symptom

When two installed copies of @module-federation/enhanced load in one webpack process (for example the app's copy and the one @module-federation/node depends on), the second copy throws as soon as its plugin applies:

ObjectMiddleware.register: serializer for enhanced/lib/container/ContainerExposedDependency/null is already registered

It fails at module load, with or without cache: { type: 'filesystem' }.

Root cause

Every serializable class called webpack's makeSerializable(Class, 'enhanced/lib/...') with a fixed key. Webpack's serializer registry is process-wide and throws when a key is registered twice, so the second copy cannot load.

Fix

All 16 call sites now go through src/lib/makeSerializable.ts, which passes the copy's install directory as webpack's name argument. Each copy gets its own key, and the key stays the same across runs for a given install.

Skipping the duplicate registration was rejected. The second copy's classes would have no serializer, so webpack could not persist its modules. It would also make cache restore depend on which copy loaded first, even when the two copies are different versions. With per-copy keys, each copy's cache entries are restored by that copy's own classes. Existing caches are not affected in practice. Upgrading enhanced changes its build dependencies, which invalidates the pack before any entry is read.

Test plan

  • test/compiler-unit/container/duplicateEnhancedCopies.test.ts runs a child Node process that loads the built dist from two directories with one shared webpack. It builds with ModuleFederationPlugin from each copy using the filesystem cache, then rebuilds. The test asserts no errors or cache warnings, and that the remote, consume, and provide modules are restored from the cache on the second build (0 rebuilt). The test fails on main with the error above and passes with the fix.
  • pnpm --filter @module-federation/enhanced test passes (463 + 6 tests).

Related open PRs

Two installed copies of enhanced in one process both registered their
classes under the same 'enhanced/lib/...' key, and webpack's global
serializer registry throws on the second registration.
@changeset-bot

changeset-bot Bot commented Sep 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b63693

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-25T15:22:58.713311Z 8b63693 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.

@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@8b63693

@module-federation/cli

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

create-module-federation

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

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/metro-plugin-rock

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/observability-plugin

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

@module-federation/playground

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/rstest

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: 8b63693

@github-actions

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.7 kB +981 B (+0.1%) 672 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB -10 B (-0.4%) 2.4 kB -32 B (-1.3%)
@module-federation/core 1.0 kB no change 1.0 kB -33 B (-3.0%)
@module-federation/devtools 30.3 kB no change 30.3 kB -24 B (-0.1%)
@module-federation/enhanced 2.7 kB no change 2.8 kB -43 B (-1.5%)
@module-federation/metro-plugin-rnc-cli 416 B -1 B (-0.2%) 435 B -26 B (-5.6%)
@module-federation/node 9.1 kB -1 B (-0.0%) 9.2 kB -28 B (-0.3%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 22.3 kB -18 B (-0.1%) 23.8 kB -11 B (-0.0%) +1.6 kB +7 B

Total dist (raw): 23.41 MB (+981 B (+0.0%))
Total ESM gzip: 111.7 kB (no change)
Total web bundle (gzip): 253.4 kB (-12 B (-0.0%))
Total node bundle (gzip): 255.6 kB (-186 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.

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