Skip to content

fix(runtime-core): cache synchronous shared factories - #4998

Merged
2heal1 merged 3 commits into
mainfrom
fix/runtime-core-set-shared-lib
Aug 19, 2026
Merged

fix(runtime-core): cache synchronous shared factories#4998
2heal1 merged 3 commits into
mainfrom
fix/runtime-core-set-shared-lib

Conversation

@2heal1

@2heal1 2heal1 commented Aug 19, 2026

Copy link
Copy Markdown
Member

Cache factories returned by synchronous shared getters in the registered share record so subsequent loadShareSync calls reuse the loaded factory.

The existing behavior dates back to the v1 implementation, where setShared returned immediately for an existing version. In the current runtime this leaves the share marked as loaded without a lib, causing later synchronous loads to invoke get again. The merge now fills lib only when the registered share does not already have one, preserving the existing provider and factory precedence.

A regression test verifies that the getter runs once and that the factory is stored in the share scope.

Validation:

  • pnpm exec turbo run test --filter=@module-federation/runtime-core --force (12 test files, 97 tests passed)
  • pnpm run ci:local --only=build-and-test (44 package builds and 60 affected test tasks passed)
  • Changeset scope/status validation for @module-federation/runtime-core patch
  • pnpm exec prettier --check . reports the unchanged baseline file packages/playground/src/generated/bridgeRuntimeFiles.ts; the CI changed-file format check passes for all files in this PR

@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fd3a32e

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

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

@module-federation/cli

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

create-module-federation

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

@module-federation/dts-plugin

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

@module-federation/enhanced

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

@module-federation/error-codes

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

@module-federation/esbuild

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

@module-federation/managers

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

@module-federation/manifest

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

@module-federation/metro

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

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

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

@module-federation/metro-plugin-rnef

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

@module-federation/metro-plugin-rock

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

@module-federation/modern-js

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

@module-federation/modern-js-v3

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

@module-federation/native-federation-tests

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

@module-federation/native-federation-typescript

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

@module-federation/nextjs-mf

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

@module-federation/node

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

@module-federation/observability-plugin

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

@module-federation/playground

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

@module-federation/retry-plugin

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

@module-federation/rsbuild-plugin

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

@module-federation/rspack

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

@module-federation/rspress-plugin

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

@module-federation/rstest

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

@module-federation/runtime

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

@module-federation/runtime-core

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

@module-federation/runtime-tools

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

@module-federation/sdk

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

@module-federation/storybook-addon

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

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

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

@module-federation/treeshake-frontend

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

@module-federation/treeshake-server

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

@module-federation/typescript

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

@module-federation/utilities

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

@module-federation/webpack-bundler-runtime

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

@module-federation/bridge-react

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

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

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

@module-federation/bridge-shared

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

@module-federation/bridge-vue3

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

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

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

commit: fd3a32e

@2heal1
2heal1 marked this pull request as ready for review August 19, 2026 08:36
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Report

11 package(s) changed, 32 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/bridge-vue3 182.3 kB +29 B (+0.0%) 26.4 kB +6 B (+0.0%)
@module-federation/inject-external-runtime-core-plugin 5.2 kB -26 B (-0.5%) 519 B no change
@module-federation/playground 28.88 MB -561 B (-0.0%) 45.2 kB no change
@module-federation/runtime-core 299.5 kB +72 B (+0.0%) 570 B no change
@module-federation/runtime-tools 7.8 kB +65 B (+0.8%) 142 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/bridge-vue3 19.5 kB +5 B (+0.0%) 19.7 kB +6 B (+0.0%)
@module-federation/cli 2.3 kB -1 B (-0.0%) 2.4 kB -31 B (-1.3%)
@module-federation/core 1.0 kB -2 B (-0.2%) 1.0 kB -33 B (-3.0%)
@module-federation/devtools 30.3 kB -2 B (-0.0%) 30.3 kB -25 B (-0.1%)
@module-federation/enhanced 2.7 kB no change 2.8 kB -42 B (-1.5%)
@module-federation/metro-plugin-rnc-cli 416 B no change 435 B -25 B (-5.4%)
@module-federation/node 9.1 kB +1 B (+0.0%) 9.2 kB -28 B (-0.3%)
@module-federation/runtime-core 15.6 kB +5 B (+0.0%) 15.3 kB +5 B (+0.0%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 21.7 kB -13 B (-0.1%) 23.3 kB -9 B (-0.0%) +1.6 kB +4 B

Total dist (raw): 35.90 MB (-421 B (-0.0%))
Total ESM gzip: 109.9 kB (+6 B (+0.0%))
Total web bundle (gzip): 239.0 kB (+6 B (+0.0%))
Total node bundle (gzip): 241.2 kB (-173 B (-0.1%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.8 kB (no change)
Tracked ./bundler node bundle (gzip): 4.8 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.

@2heal1
2heal1 merged commit 08fdc4d into main Aug 19, 2026
25 checks passed
@2heal1
2heal1 deleted the fix/runtime-core-set-shared-lib branch August 19, 2026 11:59
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