feat(web): sync per-user locale preference end-to-end (persist + session-load apply) #1181

Merged
chris merged 1 commit from feature/i18n-locale-sync into main 2026-10-13 03:27:32 +02:00
Owner

Wires the per-user locale preference (spec 058 / ADR 0111, backend PR #1180, frontend infra PR #1178) end-to-end in the web app.

What changed

  • SessionUser (src/lib/session/session.ts) gains locale: string | null, populated at both store-construction sites:
    • setup login: POST /api/session returns UserAccount without locale, so GET /api/session is fetched in parallel with getSetupStatus() (no extra sequential round-trip); non-fatal on failure (falls back to null → no sync).
    • register: fresh account → locale: null.
  • CurrentSession (src/lib/api/upload.ts) exposes locale?: string | null (optional so a not-yet-upgraded API build still type-checks; undefined treated as null).
  • persistLocaleToAccount(locale): PUT /api/session/preferences via the existing apiClient, never rejects (console.warn on failure), keepalive: true so the request survives the page reload setLocale() triggers right after — without it the account would stay out of sync and the choice would be reverted on the next session load.
  • Wiring:
    • profile switcher (Konto tab): persistLocaleToAccount(value) alongside setLocale(value) (cookie remains the immediate transport).
    • AppShell refreshHeaderSelfPerson + setup login: syncLocaleFromAccount(session.locale) so a stored account locale beats a stale browser cookie. Match/unsupported/null no-op guards against reload loops.

Verification (all green locally)

  • npm run check → 0 errors (18 pre-existing warnings in untouched files, same as baseline)
  • npm run build → ✓ built in 33.77s
  • npm run test:unit → 200/200 (26 files), incl. new localeSync.spec.ts (8 tests: PUT method/url/body/keepalive, never-rejects on 400/401/network failure, sync apply/no-op/unsupported) and session.spec.ts (3 tests). Specs pass even on a fresh checkout without compiled src/lib/paraglide/.

Behavioral caveats

  • If the PUT fails (warn in console), the next session load reverts this browser to the account locale — accepted per spec (account is source of truth on session load).
  • The persisted choice applies on next session load / reload, not reactively mid-visit — matches the existing cookie+reload model.
  • AppShell does not hydrate the SessionUser store (pre-existing design, documented at line 181: only setup/register populate it); it only gained the sync call. Store construction sites updated as required.
  • da/de copy untouched this round (no new user-visible strings).

EXTRACTION.md: localeSync wiring marked done (wave-5 line updated).

Wires the per-user locale preference (spec 058 / ADR 0111, backend PR #1180, frontend infra PR #1178) end-to-end in the web app. ## What changed - `SessionUser` (src/lib/session/session.ts) gains `locale: string | null`, populated at both store-construction sites: - **setup login**: `POST /api/session` returns `UserAccount` without locale, so `GET /api/session` is fetched in parallel with `getSetupStatus()` (no extra sequential round-trip); non-fatal on failure (falls back to `null` → no sync). - **register**: fresh account → `locale: null`. - `CurrentSession` (src/lib/api/upload.ts) exposes `locale?: string | null` (optional so a not-yet-upgraded API build still type-checks; `undefined` treated as null). - `persistLocaleToAccount(locale)`: `PUT /api/session/preferences` via the existing `apiClient`, **never rejects** (console.warn on failure), `keepalive: true` so the request survives the page reload `setLocale()` triggers right after — without it the account would stay out of sync and the choice would be reverted on the next session load. - Wiring: - profile switcher (Konto tab): `persistLocaleToAccount(value)` alongside `setLocale(value)` (cookie remains the immediate transport). - AppShell `refreshHeaderSelfPerson` + setup login: `syncLocaleFromAccount(session.locale)` so a stored account locale beats a stale browser cookie. Match/unsupported/null no-op guards against reload loops. ## Verification (all green locally) - `npm run check` → **0 errors** (18 pre-existing warnings in untouched files, same as baseline) - `npm run build` → ✓ built in 33.77s - `npm run test:unit` → **200/200** (26 files), incl. new `localeSync.spec.ts` (8 tests: PUT method/url/body/keepalive, never-rejects on 400/401/network failure, sync apply/no-op/unsupported) and `session.spec.ts` (3 tests). Specs pass even on a fresh checkout without compiled `src/lib/paraglide/`. ## Behavioral caveats - If the PUT fails (warn in console), the next session load reverts this browser to the account locale — accepted per spec (account is source of truth on session load). - The persisted choice applies on *next* session load / reload, not reactively mid-visit — matches the existing cookie+reload model. - `AppShell` does **not** hydrate the `SessionUser` store (pre-existing design, documented at line 181: only setup/register populate it); it only gained the sync call. Store construction sites updated as required. - da/de copy untouched this round (no new user-visible strings). EXTRACTION.md: localeSync wiring marked done (wave-5 line updated).
feat(web): sync per-user locale preference end-to-end (persist + session-load apply)
Some checks failed
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Failing after 8m33s
714f9c6917
- SessionUser gains locale: string|null, populated at both store-construction
  sites (setup login reads GET /api/session in parallel with setup status;
  register = fresh account -> null); CurrentSession exposes optional locale
  (spec 058 / ADR 0111).
- persistLocaleToAccount(): PUT /api/session/preferences via apiClient,
  keepalive so it survives the setLocale() reload, never rejects (warn only).
- Profile switcher persists alongside setLocale; AppShell
  refreshHeaderSelfPerson and setup login call syncLocaleFromAccount so the
  account locale beats a stale cookie (match no-op guards reload loops).
- EXTRACTION.md: localeSync wiring marked done (wave-5 line updated).
- Tests: localeSync.spec.ts (8) + session.spec.ts (3).
chris force-pushed feature/i18n-locale-sync from 714f9c6917
Some checks failed
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Failing after 8m33s
to c6946379d8
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 2s
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Android unit tests and debug APK (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5m36s
2026-10-13 03:21:32 +02:00
Compare
chris merged commit 2b8e0a19f4 into main 2026-10-13 03:27:32 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1181
No description provided.