Skip to content

fix(runtime): preserve shared identity while invalidating host consumers - #5049

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

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

Conversation

@2heal1

@2heal1 2heal1 commented Sep 10, 2026

Copy link
Copy Markdown
Member

Description

Remote removal previously either skipped host invalidation when a provider supplied shared modules, or cleared the provider execution cache and recreated its singleton. This patch invalidates host remote/consumer caches independently while retaining provider caches needed by external shared consumers or pending shared loads. Runtime-core now checks shared ownership even after the provider leaves the instance registry.

Tests cover host eviction, loaded/loading shares, absent provider registration, and strict shared/lazy dependency identity in real Rspack artifacts. Existing undefined vi.fn usages in the touched runtime-core tests were corrected to imported rs.fn. Adds patch changesets for runtime-core and webpack-bundler-runtime.

Draft: R1 remains incomplete. Conservative provider retention prevents collection of unrelated provider payload. Modern SSR CI fails remove-remote-shared-cache.cy.js:40 (nonSharedPayloadCollected is false); this assertion is unchanged. Selective provider cleanup is required before the production memory requirement can pass. Parent metadata and adapter disposal are also still open.

Validation: builds passed; runtime-core 134/134 and bundler-runtime 109/109 tests passed. Local Rspack + Modern artifacts: 8 pass / 5 TODO; installed canary: 7 pass / 5 TODO / 1 explicit Modern skip. Two shared TODOs are now passing regressions. Modern remote-cache E2E passed in this run, shared-cache E2E failed as above. Changed files pass formatting; full-repo format still reports 683 existing/generated files. Changeset scope/status passed. Exact commands and skipped coverage are recorded in tools/ssr-cache/VALIDATION.md. No claim of production readiness or full provider GC.

Related Issue

Continues the R0 baseline merged in #5048. No separate issue linked.

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: 8bc7b9b

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

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

@module-federation/cli

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

create-module-federation

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

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/metro-plugin-rock

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/observability-plugin

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

@module-federation/playground

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/rstest

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: 8bc7b9b

@2heal1
2heal1 marked this pull request as ready for review September 10, 2026 08:52
@2heal1
2heal1 merged commit 2ed88f5 into feat/mf-ssr-clear-cache Sep 10, 2026
6 checks passed
@2heal1
2heal1 deleted the fix/ssr-cache-shared-lifecycle branch September 10, 2026 08:52
@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-10T08:56:34.804603Z 8bc7b9b Draft marked ready
ℹ️ 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: 8bc7b9b0fa

ℹ️ 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".

shareVersion,
]);
}
if (shared.useIn.length || shared.loading) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not retain providers for already-settled share loads

When a provider has loaded a shared module but has no external consumers, SharedHandler.loadShare sets loaded = true but leaves the resolved promise in shared.loading. Consequently, after this code removes the provider itself from useIn, shared.loading remains truthy and permanently sets preserveRemoteRuntime, retaining the removed provider's global and execution cache. This regresses cleanup for self-consumed shares; only an unsettled load (for example, shared.loading && !shared.loaded) should trigger this retention.

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