Skip to content

fix(runtime-core): clear rejected remote-entry promises from globalLoading - #5006

Merged
2heal1 merged 2 commits into
module-federation:mainfrom
tonoizer:fix/runtime-core-clear-rejected-globalLoading
Aug 28, 2026
Merged

fix(runtime-core): clear rejected remote-entry promises from globalLoading#5006
2heal1 merged 2 commits into
module-federation:mainfrom
tonoizer:fix/runtime-core-clear-rejected-globalLoading

Conversation

@tonoizer

Copy link
Copy Markdown
Contributor

Problem

getRemoteEntry stores the in-flight load promise in globalLoading[uniqueKey]. On terminal rejection the .catch rethrows without deleting the cache entry, so later callers keep receiving the same rejected promise.

Retry-plugin only deletes the key in beforeExecuteRetry. Hosts without retry-plugin (or after exhausted retries) still poison the shared cache. Successful loads must remain cached.

Root cause

In packages/runtime-core/src/utils/load.ts, after assigning the loading promise to globalLoading[uniqueKey], a rejected promise stayed in the cache indefinitely. There was no cleanup on terminal failure at the runtime-core layer.

Why fix this in runtime-core (not only retry-plugin)

  • runtime-core getRemoteEntry: Own the globalLoading cache lifecycle — share in-flight work, keep successes, clear terminal failures so a later call can start a new load.
  • retry-plugin: Optional policy for how to retry (delays, domains, query busting). It should not be the only place that unblocks a poisoned cache.

Putting cleanup in runtime-core fixes all consumers; retry-plugin remains complementary for active retry orchestration.

Behavior after this change

Scenario Behavior
Successful load Promise stays in globalLoading (unchanged).
Concurrent callers Share one in-flight promise (unchanged).
Rejected load, then later call Rejected entry removed; second call starts a new load (loader runs again).
Permanent/repeated failure Each failed attempt is cleared; cache is not poisoned by an old rejection.
Older rejection vs newer in-flight request Cleanup uses identity check (globalLoading[uniqueKey] === loading) so an older rejection cannot delete a newer deferred request.

No unbounded auto-retries are introduced. The original loading promise identity remains in the cache (cleanup is a side-effect thenable, not a replacement).

Related (not duplicated)

Test plan

  • runtime-core load.spec.ts — 22 passed
  • runtime-core full package test suite — 126 passed
  • Regression coverage: success remains cached; concurrent share; reject then succeed (loader twice); permanent failure does not poison; older rejection cannot delete newer deferred request

…ading

Rejected getRemoteEntry loads left their promise in globalLoading forever,
so later callers reused the failed thenable unless retry-plugin deleted the
key. Clear the cache entry on terminal rejection while keeping successful
loads cached, and use an identity check so an older rejection cannot delete
a newer in-flight request.
@changeset-bot

changeset-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7299797

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

ℹ️ 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 +455 to +457
loading.then(undefined, () => {
if (globalLoading[uniqueKey] === loading) {
delete globalLoading[uniqueKey];

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 Add a patch changeset for the runtime behavior change

This changes the published behavior of @module-federation/runtime-core, but the commit contains no .changeset/*.md file. Consequently, the release plan will not record or version this fix, so consumers may never receive it through the normal release process; add a patch changeset covering @module-federation/runtime-core and its fixed package group.

AGENTS.md reference: AGENTS.md:L221-L227

Useful? React with 👍 / 👎.

The rejected-promise cleanup changes published runtime-core behavior and needs a changeset so the fix ships in a release.
@2heal1
2heal1 merged commit 92afef1 into module-federation:main Aug 28, 2026
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