Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: framework-agnostic remote exports, deferred loaded-first, and unified SSR gates#742

Merged
gioboa merged 19 commits into
module-federation:mainfrom
tonoizer:fix/remote-exports-ssr-capabilities
Jun 9, 2026
Merged

fix: framework-agnostic remote exports, deferred loaded-first, and unified SSR gates#742
gioboa merged 19 commits into
module-federation:mainfrom
tonoizer:fix/remote-exports-ssr-capabilities

Conversation

@tonoizer

Copy link
Copy Markdown
Contributor
  • Replace the React-specific remote Proxy with real module resolution (__mfUnwrapRemoteDefault + top-level await) for build, version-first dev, and SSR.
  • Restore deferred client loading for shareStrategy: 'loaded-first' via a minimal framework-agnostic proxy (__mfCreateDeferredRemoteProxy); SSR still awaits the real remote module.
  • Centralize SSR feature flags in getSsrCapabilities() so ssrEntryLoader injection and dev SSR bootstrap stay aligned (Vite 8+ dev; build/preview on all supported Vite majors).
  • Serve *.exposes.js over HTTP in dev for SSR fetch chains (builds on fix(ssr): load federated remotes in general Vite SSR setupsΒ #723).

Motivation

The previous React-only proxy fixed React.lazy / hydration quirks but was wrong for SSR (a proxy is not a real module) and blocked other frameworks. A single always-await path also regressed loaded-first, which must not call loadRemote until a remote export is actually read on the client.

This PR keeps one await-based path for SSR and version-first, and only defers on the browser when shareStrategy: 'loaded-first'.

Examples branch (manual verification)

Validated against the SSR examples on: https://github.com/tonoizer/module-federation-vite-examples/tree/feat/ssr-vue-react-demos

(vue-ssr, react-ssr, tanstack, nuxt β€” build, preview, dev, Playwright; default version-first, no shareStrategy required in demos)

tonoizer and others added 3 commits May 23, 2026 14:25
Await real remote modules for SSR and version-first; defer loaded-first on the
client only. Centralize ssrEntryLoader and dev SSR bootstrap in getSsrCapabilities.

Co-authored-by: Cursor <[email protected]>
Bring in getRemoteFromId for scoped/overlapping remote names and React
lazy-safe proxies from main, while keeping framework-agnostic deferred
exports for loaded-first and Nuxt dev entry.mount init injection.

Co-authored-by: Cursor <[email protected]>
Emit separate client and server remote virtual modules when environments.ssr
is active, with unified typeof-window fallback for single-environment setups.
Include shareStrategy in remote wrapper cache keys.

Skip duplicate SvelteKit host-init injection when HTML is patched twice.

Co-authored-by: Cursor <[email protected]>

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

ℹ️ 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 thread src/virtualModules/virtualRemotes.ts Outdated
Comment thread src/virtualModules/virtualRemotes.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented May 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@module-federation/vite@742

commit: e047da7

Use a thenable that starts loadRemote only when awaited so dynamic
import() waits for the real module without eager fetch on static import.

Co-authored-by: Cursor <[email protected]>

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your help @tonoizer

Comment thread src/virtualModules/virtualRemotes.ts Outdated
Comment thread src/virtualModules/virtualRemotes.ts Outdated
tonoizer and others added 3 commits May 27, 2026 09:43
Extend loaded-first client deferral to production builds (SSR still awaits
the real module). Cache remote virtual modules by consumer so client and
server wrappers are not overwritten. Introduce RemoteInitMode for clarity.

Co-authored-by: Cursor <[email protected]>
@tonoizer tonoizer requested a review from gioboa May 29, 2026 06:56
@tonoizer

Copy link
Copy Markdown
Contributor Author

@gioboa Do I need to change additional things or is this PR alright?

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unfortunately this PR is adding top level awaits and this is problematic with Nuxt and other frameworks. Can you replace TLAs with a chain of promises? We are already doing that in the codebase.

tonoizer and others added 3 commits June 4, 2026 21:30
Resolve virtualShared_preBuild.ts: keep lazy workspace singleton exports
(promise chains, no TLA) alongside upstream loadShare materialization helpers.

Co-authored-by: Cursor <[email protected]>
@tonoizer tonoizer requested a review from gioboa June 5, 2026 06:08
@gioboa gioboa force-pushed the fix/remote-exports-ssr-capabilities branch from 4294cda to e047da7 Compare June 9, 2026 23:35
@gioboa gioboa merged commit b07ce14 into module-federation:main Jun 9, 2026
29 of 37 checks passed

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your help @tonoizer πŸ™
This is a great improvement

@gioboa

gioboa commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Tests With Different Frameworks

Screenshot 2026-06-10 at 01 47 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants