Skip to content

Commit 9c49d3d

Browse files
committed
fix(chat, strategy-curator): set output.assetPrefix so federated sub-chunks resolve against the remote's own origin, not the host's
Both remotes had `dev.assetPrefix` set (correct for local federation dev) but no `output.assetPrefix` — the field that also applies to production builds. Without it, a remote's async sub-chunks (e.g. chat's __federation_expose_mount.js) resolve as relative paths against whatever page loaded them — the shell's origin, not the remote's — so on the real deploy every chat sub-chunk 404'd against augment.didi.sh and got back the shell's own SPA-fallback HTML, which the browser then tried to eval as JS ("SyntaxError: Unexpected token '<'"). Caught via a live browser check against the actual deployed augment.didi.sh, not a local test — this only reproduces cross-origin. New PUBLIC_CHAT_ASSET_PREFIX / PUBLIC_STRATEGY_CURATOR_ASSET_PREFIX env vars (localhost defaults preserved for dev), threaded through as Docker build args. Verified locally: built each image with the real deployed origin as the arg, extracted dist/, confirmed remoteEntry.js references the correct origin instead of relative paths. Files changed: - apps/chat/rsbuild.config.ts - apps/chat/Dockerfile - apps/strategy-curator/rsbuild.config.ts - apps/strategy-curator/Dockerfile
1 parent f6d7ec3 commit 9c49d3d

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

apps/chat/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ COPY shell ./shell
1818
RUN pnpm install --frozen-lockfile
1919

2020
ARG PUBLIC_WS_URL
21+
ARG PUBLIC_CHAT_ASSET_PREFIX
2122
ENV PUBLIC_WS_URL=$PUBLIC_WS_URL
23+
ENV PUBLIC_CHAT_ASSET_PREFIX=$PUBLIC_CHAT_ASSET_PREFIX
2224
RUN pnpm --filter @augment-it/chat build
2325

2426
FROM node:22-alpine

apps/chat/rsbuild.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
77
// .css side-effect imports). See changelog entries:
88
// - 2026-05-21_03 — federation-meets-Svelte-5 lessons
99
// - 2026-05-23_01 — in-app chat v0.0.1 (this surface)
10+
// Own-origin asset prefix — a federated remote's sub-chunks (async imports,
11+
// __federation_expose_mount, etc.) resolve against whatever `assetPrefix`
12+
// this build was compiled with, NOT the host page's origin. Missing this
13+
// in production silently 404s every chunk beyond remoteEntry.js itself
14+
// against the SHELL's origin (which serves its own SPA fallback HTML for
15+
// unknown paths) — "SyntaxError: Unexpected token '<'" is that HTML being
16+
// eval'd as JS. `dev.assetPrefix` alone only covers the local dev server;
17+
// `output.assetPrefix` is the field that also applies to production builds.
18+
const ASSET_PREFIX = process.env.PUBLIC_CHAT_ASSET_PREFIX || 'http://localhost:3006';
19+
1020
export default defineConfig({
1121
plugins: [
1222
pluginSvelte(),
@@ -25,6 +35,7 @@ export default defineConfig({
2535
output: {
2636
target: 'web',
2737
overrideBrowserslist: ['last 2 Chrome versions', 'last 2 Firefox versions', 'last 2 Safari versions'],
38+
assetPrefix: ASSET_PREFIX,
2839
},
2940
tools: {
3041
swc: {
@@ -41,6 +52,6 @@ export default defineConfig({
4152
cors: { origin: ['http://localhost:3100'] }, // the federation shell
4253
},
4354
dev: {
44-
assetPrefix: 'http://localhost:3006',
55+
assetPrefix: ASSET_PREFIX,
4556
},
4657
});

apps/strategy-curator/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ COPY shell ./shell
1818
RUN pnpm install --frozen-lockfile
1919

2020
ARG PUBLIC_WS_URL
21+
ARG PUBLIC_STRATEGY_CURATOR_ASSET_PREFIX
2122
ENV PUBLIC_WS_URL=$PUBLIC_WS_URL
23+
ENV PUBLIC_STRATEGY_CURATOR_ASSET_PREFIX=$PUBLIC_STRATEGY_CURATOR_ASSET_PREFIX
2224
RUN pnpm --filter @augment-it/strategy-curator build
2325

2426
FROM node:22-alpine

apps/strategy-curator/rsbuild.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
66
// sources (metadata-first → fetch via Jina/PDF), pull extracts. Writes only
77
// through workspace capabilities (strategy.* / source.* / extract.* / tag.*).
88
// See context-v/specs/Strategy-Curator-Entry-Point-for-Augment-It.md.
9+
// Own-origin asset prefix — see apps/chat/rsbuild.config.ts's comment for
10+
// the full rationale (a federated remote's sub-chunks resolve against
11+
// whatever assetPrefix it was compiled with, not the host's origin;
12+
// dev.assetPrefix alone doesn't cover production builds).
13+
const ASSET_PREFIX = process.env.PUBLIC_STRATEGY_CURATOR_ASSET_PREFIX || 'http://localhost:3017';
14+
915
export default defineConfig({
1016
plugins: [
1117
pluginSvelte(),
@@ -24,6 +30,7 @@ export default defineConfig({
2430
output: {
2531
target: 'web',
2632
overrideBrowserslist: ['last 2 Chrome versions', 'last 2 Firefox versions', 'last 2 Safari versions'],
33+
assetPrefix: ASSET_PREFIX,
2734
},
2835
tools: {
2936
swc: {
@@ -38,6 +45,6 @@ export default defineConfig({
3845
cors: { origin: ['http://localhost:3100'] }, // the federation shell
3946
},
4047
dev: {
41-
assetPrefix: 'http://localhost:3017',
48+
assetPrefix: ASSET_PREFIX,
4249
},
4350
});

0 commit comments

Comments
 (0)