Skip to content

fix(ui): let an embedding app restore the chosen language - #981

Merged
runkids merged 3 commits into
runkids:mainfrom
AlexisSerneels:fix/ui-locale-embedded
Nov 23, 2026
Merged

runkids merged 3 commits into
runkids:mainfrom
AlexisSerneels:fix/ui-locale-embedded

Conversation

@AlexisSerneels

@AlexisSerneels AlexisSerneels commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)
  • Approved feature or large change (the linked issue has the approved label)

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, so skillshare:locale is lost and getInitialLocale() falls back to navigator.language. The theme already works around this with ?theme= and postMessage; the locale did not.

Change:

  • getInitialLocale() reads a ?lang= URL parameter first (then saved choice, then browser languages), like ?theme=.
  • When embedded, 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=): #982

Outside the app nothing changes: without ?lang= the behavior is the same, and nothing is posted when the UI is not in a frame.

Checklist

  • I've read CONTRIBUTING.md, including its AI-assisted contributions section
  • I've reviewed every line of the diff and can explain it
  • Tests included and passing (make check) — for code changes: 2 tests added in ui/src/i18n/i18n.test.ts; vitest run src/i18n, pnpm typecheck, oxlint and oxfmt --check pass locally. make check was not run.
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T09:28:25.482351Z c13747e 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.

@AlexisSerneels

AlexisSerneels commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Linked to: #982

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread ui/src/i18n/locales.ts Outdated
Comment on lines +90 to +93
const fromUrl = normalizeLocale(new URLSearchParams(search).get(LOCALE_URL_PARAM));
if (fromUrl) {
try {
localStorage.setItem(LOCALE_STORAGE_KEY, fromUrl);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@runkids

runkids commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Thanks for this. Tests, typecheck and lint pass in the devcontainer. I found one bug:

A reload inside the frame brings back the old ?lang= and undoes the user's choice.

getInitialLocale() lets ?lang= win and writes it to storage on every load, but the frame's URL keeps the value it was opened with:

  1. The app opens /?theme=clean&lang=fr. The index route renders the dashboard, so the query stays in the URL.
  2. The user picks English in the header language popover. There is no navigation, so the URL still says lang=fr.
  3. The page calls window.location.reload(). The upgrade flow in UpdateDialog / DoctorPage (lib/upgradeWorkflow.ts) and the ErrorBoundary reload button both do this.
  4. The page reads lang=fr again. It shows French and writes fr back to storage.

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 en from locale-change. Theme doesn't hit this because the app answers with theme-push. Locale has no push channel.

Suggested fix: once ?lang= has been read, remove it from the URL before the router mounts, the same way applyUrlThemeParam() runs at module level. A reload then can't read a stale value, and route-change won't report one to the app:

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
@AlexisSerneels

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the repro, you're right. Fixed in a828153:

  • ?lang= is now read once at module load (applyUrlLocaleParam(), same pattern as applyUrlThemeParam()), saved, then removed with history.replaceState; other params, path and hash are kept.
  • Added ui/src/i18n/urlLocale.test.tsx with your scenario (open with lang=fr, pick English, reload → stays en), which fails without the fix.

Full UI vitest suite, typecheck, oxlint and oxfmt pass locally.

@runkids
runkids merged commit bed9bb2 into runkids:main Nov 23, 2026
10 checks passed
runkids added a commit to runkids/skillshare-app that referenced this pull request Nov 23, 2026
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]>
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