Skip to content

fix(runtime): dispose and rebind bundler cache adapters - #5052

Merged
2heal1 merged 1 commit into
feat/mf-ssr-clear-cachefrom
fix/ssr-cache-adapter-lifecycle
Sep 10, 2026
Merged

2heal1 merged 1 commit into
feat/mf-ssr-clear-cachefrom
fix/ssr-cache-adapter-lifecycle

Conversation

@2heal1

@2heal1 2heal1 commented Sep 10, 2026

Copy link
Copy Markdown
Member

Description

After an application rebuild reused its MF instance, the removal plugin still called the first bundler and installation stacked instance wrappers/listeners. Make the plugin query live bindings from the instance and return an idempotent disposer from installClearCache, also available as federation.disposeClearCache.

A shared per-instance registry coordinates multiple bundlers and separately bundled copies. The last detach restores owned methods and removes its listener, preserves later third-party wrappers, and releases captured runtime references. Pending cache cleanup prevents detachment; saved clear functions reject after disposal. Remove/force-registration cleanup reaches all live bindings and waits for their outcomes. The unused moduleCache.set generation wrapper is removed.

The application owner must drain work before disposal. This is an adapter primitive, not Modern admission/drain or full application GC. Persistent MF/shared/business references can still retain code.

Validation: runtime-tools build 6/6; complete bundler package 116/116 tests; strict real Rspack + Modern HTTP artifact baseline 23/23, zero TODOs/skips, including the three previously stale-adapter cases and a retained-handle WeakRef check. Full Modern SSR CI passes both remote-cache and shared-cache/GC specs. Existing intermittent capture failure did not reproduce and is not claimed fixed. Changed-file formatting, diff checks and changeset planning pass; full-repo Prettier still reports 683 pre-existing/generated files. Unchanged runtime-core/native Rspack suites and unrelated CI jobs were not rerun. Exact commands and limits: tools/ssr-cache/VALIDATION.md. No publication.

Related Issue

Continues merged #5051 and the SSR cache RFC R1 adapter lifecycle work.

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 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f087e15

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/webpack-bundler-runtime Patch
@module-federation/enhanced Patch
@module-federation/esbuild Patch
@module-federation/nextjs-mf Patch
@module-federation/runtime-tools Patch
@module-federation/modern-js-v3 Patch
@module-federation/modern-js 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
@module-federation/rspack Patch
@module-federation/inject-external-runtime-core-plugin 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/runtime-core 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/bridge-react-webpack-plugin Patch
@module-federation/bridge-react Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-vue3 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 10, 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-10T09:52:53.778613Z f087e15 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 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

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

@module-federation/cli

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

create-module-federation

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

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/metro-plugin-rock

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/observability-plugin

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

@module-federation/playground

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/rstest

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: f087e15

@2heal1
2heal1 merged commit d20d8ab into feat/mf-ssr-clear-cache Sep 10, 2026
18 of 19 checks passed
@2heal1
2heal1 deleted the fix/ssr-cache-adapter-lifecycle branch September 10, 2026 09:50

@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: f087e15de1

ℹ️ 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 on lines +1237 to +1240
const targets = bindings.map((binding) => ({
binding,
target: getClearTarget({ name: remote.name, webpackRequire: binding }),
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Skip bindings without bundler remote mappings

When a reused MF instance has an attached webpack runtime whose compilation emitted no remote runtime, its optional bundlerRuntimeOptions.remotes is undefined. This new all-bindings map still includes that runtime, and captureBundlerRemoteInfoSnapshot subsequently dereferences remotesOptions.idToRemoteMap, causing force registration from another valid binding to reject and roll back. Skip bindings without mapping tables, since they have no bundler mappings to update or clear.

Useful? React with 👍 / 👎.

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