Repository navigation
fix(ui): let an embedding app restore the chosen language - #981
Conversation
The desktop app embeds this UI in an iframe at http://localhost:PORT. WebKit keeps no storage for that cross-origin frame between launches, so the saved locale is lost and the UI falls back to the system language (e.g. a French Mac reopens in French after choosing English). Read the locale from a ?lang= URL parameter first, like ?theme=, and post a locale-change message to the parent window when the user picks a language, so the app can remember it and pass it back. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011RY6nmnTA7UNpJsbsYH8Gc
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Linked to: #982 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c13747e129
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const fromUrl = normalizeLocale(new URLSearchParams(search).get(LOCALE_URL_PARAM)); | ||
| if (fromUrl) { | ||
| try { | ||
| localStorage.setItem(LOCALE_STORAGE_KEY, fromUrl); |
There was a problem hiding this comment.
Keep the locale query parameter in sync with user selections
Opening /?lang=en, choosing Japanese in the sidebar language picker, and refreshing without navigating resets the UI to English and overwrites the saved preference back to en. setLocale in I18nContext.tsx updates React state and storage but never updates or removes the original query parameter, so this URL-first initializer reapplies the old language on every reload. Consume the bootstrap parameter or synchronize it with explicit locale selections so refreshing does not undo the user's newly saved preference.
Useful? React with 👍 / 👎.
|
Thanks for this. Tests, typecheck and lint pass in the devcontainer. I found one bug: A reload inside the frame brings back the old
Repro, run against this branch: window.history.replaceState(null, '', '/?theme=clean&lang=fr');
const first = render(<I18nProvider><Probe /></I18nProvider>);
act(() => api.setLocale('en'));
first.unmount();
render(<I18nProvider><Probe /></I18nProvider>); // same URL, like reload()
expect(api.locale).toBe('en'); // fails: received 'fr'The app corrects itself on its next iframe load, because it saved Suggested fix: once const url = new URL(window.location.href);
url.searchParams.delete(LOCALE_URL_PARAM);
history.replaceState(history.state, '', url);A regression test like the repro above would cover it. |
Left in the address, ?lang= came back on any reload inside the frame (upgrade flow, error boundary) and undid a language picked since, writing the old value back to storage. Read it once at module load, like the theme parameters, save it, and remove it with history.replaceState. A regression test reproduces the reload. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011RY6nmnTA7UNpJsbsYH8Gc
|
Thanks for the review and the repro, you're right. Fixed in a828153:
Full UI vitest suite, typecheck, oxlint and oxfmt pass locally. |
The CLI UI runs in a cross-origin iframe whose localStorage WebKit does not keep between launches, so a language picked there is forgotten and the UI reopens in the system language (runkids/skillshare#982). Remember the language the CLI UI reports (locale-change message) in the shell's own storage and pass it back as ?lang= when the iframe loads, the same way the theme is carried. The CLI side shipped in runkids/skillshare#981; an older CLI UI ignores ?lang=. Co-authored-by: AlexisSerneels <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Type
proposals/only — see CONTRIBUTING.md)approvedlabel)Linked Issue
No issue opened. Bug: in the desktop app on a Mac set to French, picking English in the dashboard does not survive a relaunch; it reopens in French.
Cause: the app embeds this UI in an iframe at
http://localhost:PORT. WebKit keeps no storage for that cross-origin frame between launches, soskillshare:localeis lost andgetInitialLocale()falls back tonavigator.language. The theme already works around this with?theme=andpostMessage; the locale did not.Change:
getInitialLocale()reads a?lang=URL parameter first (then saved choice, then browser languages), like?theme=.setLocale()posts{ type: 'locale-change', locale }to the parent window so the app can remember the choice and pass it back.Companion bugfix in skillshare-app (stores the choice and passes
?lang=): #982Outside the app nothing changes: without
?lang=the behavior is the same, and nothing is posted when the UI is not in a frame.Checklist
make check) — for code changes: 2 tests added inui/src/i18n/i18n.test.ts;vitest run src/i18n,pnpm typecheck,oxlintandoxfmt --checkpass locally.make checkwas not run.