feat: add SSR remote cache clearing#4824
Conversation
✅ Deploy Preview for module-federation-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@module-federation/devtools
@module-federation/cli
create-module-federation
@module-federation/dts-plugin
@module-federation/enhanced
@module-federation/error-codes
@module-federation/esbuild
@module-federation/managers
@module-federation/manifest
@module-federation/metro
@module-federation/metro-plugin-rnc-cli
@module-federation/metro-plugin-rnef
@module-federation/metro-plugin-rock
@module-federation/modern-js
@module-federation/modern-js-v3
@module-federation/native-federation-tests
@module-federation/native-federation-typescript
@module-federation/nextjs-mf
@module-federation/node
@module-federation/observability-plugin
@module-federation/retry-plugin
@module-federation/rsbuild-plugin
@module-federation/rspack
@module-federation/rspress-plugin
@module-federation/runtime
@module-federation/runtime-core
@module-federation/runtime-tools
@module-federation/sdk
@module-federation/storybook-addon
@module-federation/third-party-dts-extractor
@module-federation/treeshake-frontend
@module-federation/treeshake-server
@module-federation/typescript
@module-federation/utilities
@module-federation/webpack-bundler-runtime
@module-federation/bridge-react
@module-federation/bridge-react-webpack-plugin
@module-federation/bridge-shared
@module-federation/bridge-vue3
@module-federation/inject-external-runtime-core-plugin
commit: |
Bundle Size Report27 package(s) changed, 14 unchanged. Package dist + ESM entry
Bundle targets
Tree-shakable entrypoints
Consumer scenarios
Total dist (raw): 6.83 MB (+15.6 kB (+0.2%)) Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as |
ad6c86f to
ad3b702
Compare
ad3b702 to
149dbbd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47905e2f7a
ℹ️ 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".
| if (options?.force) { | ||
| // remove registered remote | ||
| this.removeRemote(registeredRemote); | ||
| void this.removeRemote(registeredRemote); |
There was a problem hiding this comment.
Await removal before validating the replacement remote
When force re-registering a remote with an alias, removeRemote now defers the actual array splice until its promise continuation, so the old remote is still in targetRemotes when normalizeRemote() runs next. The alias-prefix check then matches the existing remote's same alias and throws, so registerRemotes([{ name, alias, ... }], { force: true }) regresses for aliased remotes; the old entry needs to be removed before validating/registering the replacement.
Useful? React with 👍 / 👎.
| .catch((error) => { | ||
| reportRemoveRemoteClearCacheError(error); | ||
| throw error; |
There was a problem hiding this comment.
Do not abort removal when no cache entry exists
In the bundled runtime, this hook runs before RemoteHandler.removeRemote splices the remote from options.remotes. If the remote has not been requested/generated into remotesLoadingData yet, clearCache rejects with the not-found cache error and the rethrow here prevents the remote from being removed at all, even though there was simply no bundler cache to evict. Treat that case as a no-op or otherwise let the runtime removal continue.
Useful? React with 👍 / 👎.
Summary
removeRemoteas a public runtime API and lifecycle hookValidation
pnpm --filter @module-federation/runtime-core test -- register-remotes.spec.tspnpm --filter @module-federation/runtime test -- api.spec.tspnpm --filter @module-federation/webpack-bundler-runtime test -- clearCache.spec.tspnpm --filter @module-federation/runtime-core buildpnpm --filter @module-federation/runtime buildpnpm --filter @module-federation/webpack-bundler-runtime buildNote: these commands were run with Node v22.22.2; the repo warns that it expects Node ^20.
Memory validation
Local SSR memory repro:
The host
devscript starts Node with--expose-gc, so the page can trigger GC before collecting memory rows.Expected checks:
heavy versionisv1reloaded heavy versionisv2after loadheap MBis higher thanbefore loadafter gcor one delayed GC row is lower thanafter removeRemoteafter reloadrises again after loading remote v2Then open the same route and load the generated
.heapsnapshotfiles in Chrome DevTools Memory. Compare later snapshots againstbefore load, and search forremote-heavy,remote-heavy-v2,Heavy, orremote/Heavyto inspect retained objects and retainers.