Skip to content

fix(cli): adopt every locale catalog the scaffold's server sends - #322

Merged
antosubash merged 1 commit into
mainfrom
fix/scaffold-i18n-locale-gate
Sep 10, 2026
Merged

antosubash merged 1 commit into
mainfrom
fix/scaffold-i18n-locale-gate

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Closes #321.

The bug

The sm new host template gated updateI18n on the locale changing:

if (block.locale !== activeLocale && block.messages) {

But the catalog the server sends varies by audience, not only by locale. Signing in swaps the anonymous snapshot for one including admin-only modules at the same locale (enen), so the update never fired and the admin catalog was thrown away. Every admin screen then rendered raw keys until a hard refresh.

The framework's own host already fixes this in host/client_app/i18n.ts — its comment describes this exact scenario, dashboard.home.title example included. That landed in #261; the template was last touched in #276 for an unrelated change and never got it. Every app scaffolded since has shipped the bug.

The fix

Adopt whatever catalog the server sends. A non-null messages payload is the signal that the client needs it — the backend already sends null when the cached catalog is still good (#248). updateI18n calls addResourceBundle(..., deep, overwrite), so applying it on every visit is additive and idempotent; activeLocale becomes dead and is removed.

Verification

Reproduced on a real deployment before fixing — five raw keys (dashboard.home.title, .description, .stats.total_users, .stats.active_users, .stats.modules) on the post-login redirect, all correct after a hard reload, 2/2 in fresh browser contexts. The tell was that every string on that page which renders correctly is a hardcoded literal in Home.tsx, while every string routed through t() renders raw.

  • New regression test asserts on the generated app.tsx; verified it fails against the previous template and passes with this change.
  • framework/cli/tests/: 289 passed, 2 skipped.
  • ruff format --check + ruff check clean; scripts/check_file_size.py OK.

Note

This is the second time the scaffold has shipped broken t() (cf. #83). It may be worth having the template import the same i18n.ts helpers the host uses rather than restating the wiring, so the two cannot drift again — left out of this PR to keep it to the fix.

https://claude.ai/code/session_01FGEM3MAEJ9iQ2LJLM3FCsT

The scaffold gated `updateI18n` on the locale *changing*, so it dropped the
catalog that arrives when the audience changes instead. Signing in swaps the
anonymous snapshot for one including admin-only modules at the same locale, so
the update never fired and every admin screen rendered raw keys
("dashboard.home.title") until a hard refresh.

A non-null `messages` payload is itself the server's signal that the client
needs it — the backend already sends `null` when the catalog the client holds
is still good. `updateI18n` calls `addResourceBundle(..., deep, overwrite)`,
so applying it on every visit is additive and idempotent, and `activeLocale`
becomes dead.

The host fixed this for itself in #261 (`host/client_app/i18n.ts`, whose
comment describes this exact scenario); the template was never brought across,
so every app scaffolded since has shipped the bug. Reproduced on a real
deployment: raw keys on the post-login redirect, correct after a hard reload,
2/2 in fresh browser contexts.

The regression test asserts on the generated `app.tsx` and fails against the
previous template.

Closes #321

Claude-Session: https://claude.ai/code/session_01FGEM3MAEJ9iQ2LJLM3FCsT
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review Completed 2026-09-08T08:51:43.573985Z 234c845 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying simple-module-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 234c845
Status: ✅  Deploy successful!
Preview URL: https://999e71de.simple-module-python.pages.dev
Branch Preview URL: https://fix-scaffold-i18n-locale-gat.simple-module-python.pages.dev

View logs

@antosubash
antosubash merged commit 4b09a0a into main Sep 10, 2026
13 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.

sm new template gates updateI18n on locale change — admin screens render raw i18n keys after sign-in

1 participant