Skip to content

feat: add adapter-backed remote stylesheet resolution - #34

Merged
gioboa merged 3 commits into
module-federation:mainfrom
dmchoi77:feat/remote-css-delivery
Nov 28, 2026
Merged

gioboa merged 3 commits into
module-federation:mainfrom
dmchoi77:feat/remote-css-delivery

Conversation

@dmchoi77

Copy link
Copy Markdown
Contributor

Summary

This implements the minimum scope discussed in the RFC(#16): specifier-based manifest resolution, stylesheet deduplication, and stylesheet error reporting. It extends getRemoteStylesheets("remote/Expose") to resolve manifests from Vite/Rsbuild adapter configuration, reducing manifest/expose drift, duplicate stylesheets, and silently swallowed CSS failures.

Existing TanStack Start head()/head-manager and SSR behavior remain unchanged. This does not replace the already-working pre-stream head handling or JavaScript-disabled SSR styling with a second collector.

Changes

  • Add a resolver that maps a remote/Expose specifier to the remote identity in adapter configuration. Vite injects it through a virtual module; Rsbuild uses a bundler replacement.
  • A direct remoteEntry.js is sufficient for browser module loading but does not expose expose-level CSS metadata, so the resolver normalizes it to a sibling mf-manifest.json when possible and fails explicitly when no manifest can be resolved. Custom deployment layouts use the explicit API or a caller-created resolver.
  • Deduplicate stylesheet URLs across remotes and expose stylesheet lookup failures through onError.
  • Update the Vite/Rsbuild SSR fixtures and release contract/artifact checks to use the specifier-based API.
  • No separate document collector or typed static-import inference is introduced; the existing TanStack head lifecycle and static-import ergonomics are preserved.
  • The helper connecting lazyRemote with loader-side preloading remains a follow-up improvement. The current API is usable by sharing the same specifier or providing an explicit resolver.

Validation

  • pnpm build: passed
  • pnpm typecheck: passed
  • Focused SSR E2E: 3/3 passed
  • Runtime and release contract/artifact tests: 60/60 passed

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/module-federation/tanstack/@module-federation/tanstack@34

commit: 5d60868

@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.

Nice direction. Before merge:

  • Rspack external/array remotes crash with a raw TypeError
  • Rsbuild resolver ignores client/server remote overrides
  • getRemoteStylesheets("remote/Expose") still needs resolveRemote, unlike the description
  • README lacks the new API
  • Why change vite-host's entry to mf-manifest.json?
  • Fixtures still .catch(() => []) without onError

Nits: awaited onError delays rejection; .json check matches query strings; only name/alias/entry need serializing; no tests for alias, array remotes, custom resolveManifestUrl.

@dmchoi77
dmchoi77 force-pushed the feat/remote-css-delivery branch from 86738ae to ceb8bd1 Compare November 26, 2026 13:23
@dmchoi77

Copy link
Copy Markdown
Contributor Author

@gioboa Thanks for the detailed review! I addressed the issues in the follow-up changes.

  • Rspack external and array-shaped remotes are normalized before creating the stylesheet resolver, avoiding the previous raw TypeError.
  • Rsbuild now creates separate client and server resolvers and respects client.remotes and server.remotes overrides.
  • getRemoteStylesheets("remote/Expose") now uses the adapter-provided resolver automatically. The explicit { manifestUrl, expose } form remains available for custom deployment layouts.
  • The README and Vite/Rsbuild fixtures now document and use the new API.
  • Fixture failures are reported through onError before the existing fallback is applied.
  • onError is no longer awaited, manifest URLs with query strings are handled correctly, and only the normalized remote identity fields are serialized.
  • Added coverage for aliases, external/array remotes, custom resolveManifestUrl, client/server overrides, and adapter-free fallback behavior.

The Vite host uses mf-manifest.json intentionally because remoteEntry.js is sufficient for loading modules but does not expose expose-level stylesheet metadata. The resolver still supports direct remoteEntry.js by normalizing it to a sibling mf-manifest.json when that deployment convention is valid. Callers with a different layout can use the explicit API or provide resolveManifestUrl.

@dmchoi77
dmchoi77 requested a review from gioboa November 26, 2026 13:26

@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.

I added one commit to keep the package in Vite's module graph, share remote normalization between adapter and runtime, preserve remote keys, ignore .json in query strings.

@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.

LGTM 👏 Thanks @dmchoi77

@gioboa
gioboa merged commit f15f42d into module-federation:main Nov 28, 2026
6 checks passed
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