Skip to content

fix(ssr): Drop the host-instances bridge from the prod preload - #210

Merged
Aukevanoost merged 2 commits into
mainfrom
fix/ssr-drop-host-instances-all
Nov 26, 2026
Merged

Aukevanoost merged 2 commits into
mainfrom
fix/ssr-drop-host-instances-all

Conversation

@Aukevanoost

Copy link
Copy Markdown
Contributor

The production SSR preload no longer passes hostInstances: 'all' to initNodeFederation.

Why

The orchestrator resolves host instances before it installs the import map. With 'all' and the default load, every shared singleton was therefore imported straight from node_modules, which holds Angular's partial-compilation output, not the linked build. Every @angular/* import, including the host's own server bundle, was then routed to that copy. As a result, production SSR:

  • logged JIT compilation failed for PlatformLocation, BrowserXhr and NoopAnimationDriver;
  • ran with isDevMode() === true;
  • loaded two copies of Angular's core internals: the bridged node_modules core next to the @nf-internal chunks from dist.

Production doesn't need the bridge. The host's server bundle and the remotes resolve @angular/* through the same import map, so there is one instance per package.

Verification

Smoke test on a fresh clone of angular-examples (angular/ssr, host + mfe1 + mfe2), Angular 22.2.6, orchestrator 4.10.0, Node 24.16, comparing the published 22.2.5 with this branch:

22.2.5 This branch
JIT compilation failed in server output 3 per server (host, mfe1) none
isDevMode() true false
@angular/core resolves to the bridge (nf-host:) dist/host/browser/_angular_core….js
/, /todos, /insights 200, hydrated 200, hydrated
/todos/1 not checked 200, hydrated
NG0203 none none

/todos renders mfe1's ./List, which uses @angular/core/rxjs-interop. No remote's import-map scope contains @angular/* or rxjs.

Build, typecheck, knip and the 484 unit tests pass; lint has no errors.

The dev SSR entry is unchanged: it passes its own load, which runs in the dev server's module graph.

Part of #201, native-federation/orchestrator#130

@Aukevanoost
Aukevanoost merged commit 6dbd7e3 into main Nov 26, 2026
1 check passed
Aukevanoost added a commit that referenced this pull request Nov 27, 2026
Backports 22.2.5..22.3.0 onto the Angular 21 layout.

Incoming:
- #214: @softarc/native-federation ~4.11.0; fromPackageJson() takes an
  optional base config and autoShareScope resolves projectPath against
  workspaceRoot.
- #171/#213: rewriteModulePreloads (./ssr export) for native import maps.
- #209: ngServerMode is set in exposed-module bundles.
- #210: the prod node preload no longer passes hostInstances.
- #215: NodePackageInstallTask comes from @angular-devkit/schematics/tasks.
- Tag-triggered release workflow (staged npm publish).

Angular 21 specific adaptations:
- Left out the Angular 22.3 bump: kept the -v4 name, 21.2.18 version and
  ng21 pins; bumped @softarc/native-federation to 4.11 by hand.
- Kept the `// upstream:` tags at v21.2.19 (1a728258d6) and the 21.2
  debugOptimize note.
- Dropped the remote builder, share-utils.spec.ts and
  tools/esbuild/sourcemap-ignorelist-plugin.ts as before.
- @angular/ssr 21.2 emits the same modulepreload markup as 22, so
  rewriteModulePreloads applies unchanged.
- follow-redirects@1 override raised to ^1.16.2 for a high advisory.
- pnpm-lock.yaml regenerated rather than merged.
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.

1 participant