Skip to content

Enable multizone embedding via prefixed asset URLs#96

Open
SakshiKekre wants to merge 1 commit into
mainfrom
chore/multizone-asset-prefix
Open

Enable multizone embedding via prefixed asset URLs#96
SakshiKekre wants to merge 1 commit into
mainfrom
chore/multizone-asset-prefix

Conversation

@SakshiKekre

@SakshiKekre SakshiKekre commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

What

Makes the chat embeddable as a multizone child on `policyengine.org/uk/chat` (see policyengine-app-v2 PR #1036). Matches the household-api-docs zone pattern.

How

Two files:

  • `frontend/next.config.js`: `assetPrefix: '/_zones/uk-chat'` in production builds (unprefixed in dev). Generated HTML references assets at `/_zones/uk-chat/_next/static/` instead of `/_next/static/`.
  • `frontend/vercel.json`: rewrite `/_zones/uk-chat/_next/:path*` → `/_next/:path*` so the chat host can fulfil those prefixed asset URLs without needing `basePath` (which would break the standalone preview URL).

End-to-end flow once both this and PR #1036 merge

The website (policyengine.org) rewrites:

```
/uk/chat → chat-host/
/_zones/uk-chat/_next/:path* → chat-host/_zones/uk-chat/_next/:path*
```

  1. User opens `policyengine.org/uk/chat`
  2. Website serves chat-host's HTML (chat's pages still live at `/`)
  3. HTML references assets at `/_zones/uk-chat/_next/static/*` (because of `assetPrefix`)
  4. Browser requests those from `policyengine.org/_zones/uk-chat/_next/static/*`
  5. Website rewrites to `chat-host/_zones/uk-chat/_next/static/*`
  6. Chat host's `vercel.json` strips the prefix back off → serves from `/_next/static/*`

What stays the same

Test plan

  • Preview builds successfully
  • Vercel preview at `policyengine-uk-chat-git-chore-multizone-asset-prefix-policy-engine.vercel.app` loads the chat
  • DevTools network tab shows assets requested at `/_zones/uk-chat/_next/static/*` and returning 200
  • Once merged + PR #1036 merged + production deploys settle, `policyengine.org/uk/chat` loads the chat with no console asset 404s

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyengine-uk-chat Ready Ready Preview, Comment Jun 2, 2026 5:42pm

Request Review

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

Beta preview is ready.

The chat is being embedded on policyengine.org/uk/chat as a multizone
child (see policyengine-app-v2 PR #1036). Vercel rewrites are the
mechanism; cross-origin iframes blank out for Next.js apps per
CLAUDE.md.

For the rewrites to work end-to-end, the chat's static asset URLs
need to live under a prefixed path so the website can proxy them
back through policyengine.org. Matches the household-api-docs zone
pattern (which uses the same /_zones/<name> convention).

Two coordinated files:

- frontend/next.config.js: assetPrefix '/_zones/uk-chat' in production
  builds. Dev server stays unprefixed for local development.
- frontend/vercel.json: rewrite /_zones/uk-chat/_next/:path* back to
  /_next/:path* so the chat host serves the prefixed URLs that the
  generated HTML references, without needing basePath (which would
  break the standalone preview URL).

Pages still live at "/" on the chat host, so direct previews
(policyengine-uk-chat.vercel.app) keep working unchanged.
@SakshiKekre SakshiKekre force-pushed the chore/multizone-asset-prefix branch from 1432dfc to 41a5ed5 Compare June 2, 2026 17:41
@SakshiKekre SakshiKekre changed the title Enable multizone embedding via NEXT_PUBLIC_CHAT_ASSET_PREFIX Enable multizone embedding via prefixed asset URLs Jun 2, 2026

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

Review

The mechanism is correct and nicely minimal. The phase-function config form is valid, the vercel.json rewrite is a catch-all on /_zones/uk-chat/_next/:path* so it covers _next/static, _next/image, and _next/data (query strings pass through), and the self-rewrite on the chat host is what keeps the standalone preview working with the prefix applied — that's the clever part. No existing vercel.json to conflict with.

One real gap: public/ assets referenced by absolute path aren't covered. assetPrefix only rewrites Next's _next/* build output; it does not touch files in public/ referenced by literal /... paths. And the website's multizone rewrites only proxy /uk/chat and /_zones/uk-chat/_next/* to the chat host — bare public paths resolve against policyengine.org. Two of these are on the embedded main chat page:

  • frontend/src/app/ChatPage.tsx:1451 — the header logo uses url(/favicon.svg) as a CSS mask. In the embed this requests policyengine.org/favicon.svg, which isn't rewritten → mask fails to load and the logo span renders as a solid colored box.
  • frontend/src/app/layout.tsx:8icons: { icon: "/favicon.svg" }, same unprefixed-path issue for the favicon.

(/policyengine-logo.svg in s/[token]/page.tsx is only on the share route, which isn't reached through the /uk/chat zone, so it's fine in practice.)

So the standalone preview will look correct, but policyengine.org/uk/chat will likely show a broken header logo. Options: add the specific public asset paths to the website's rewrite list, or move/serve those assets under the prefixed path and reference them prefix-aware. Worth resolving before the "no console asset 404s" checkbox can pass.

Minor: confirm the Vercel project's root directory is frontend/ so this vercel.json is actually picked up (the Next app and output: standalone suggest it is, but the rewrite silently does nothing if the root is the repo root).

Config-only change; did not run a build.

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