diff --git a/website/src/pages/AppPopoutFrame.tsx b/website/src/pages/AppPopoutFrame.tsx index c439ff095ccb..5f44c462da60 100644 --- a/website/src/pages/AppPopoutFrame.tsx +++ b/website/src/pages/AppPopoutFrame.tsx @@ -20,6 +20,7 @@ import { Btn } from '../components/ui' import BuiltinAppRoute from '../apps/BuiltinAppRoute' import AppPage from './AppPage' import { i18nT } from '../i18n/t' +import { useLanguageGeneration } from '../i18n/useLanguageGeneration' /** * The session an app in this window activated and no exit has carried yet. @@ -257,6 +258,10 @@ export default function AppPopoutFrame({ route }: { // Reflect the app in the window/taskbar title so multiple pop-outs are // distinguishable at the OS level. A core page has no app record to name it. + // The language switch is subscribed to: a store-driven re-render that lands + // before the repaint would otherwise bail out, keeping the new label but + // dropping the effect that titles the window. + useLanguageGeneration() const corePage = corePopoutPage(route) const shownLabel = (corePage ? i18nT(corePage.labelKey) : label) || i18nT('pages.appPopoutFrame.app') useEffect(() => { diff --git a/website/src/shell/appShell.tsx b/website/src/shell/appShell.tsx index e2d027d8fef1..c0fe324fb375 100644 --- a/website/src/shell/appShell.tsx +++ b/website/src/shell/appShell.tsx @@ -83,6 +83,7 @@ import { shortcutEntry } from '../lib/shortcutRegistry' import { ariaKeyshortcutsFor, useKeyboardLayout, useShortcutsEnabled } from '../hooks/useNavShortcutHint' import type { MobileRosterBarState } from '../components/MobileNavRailContext' import { i18nT } from '../i18n/t' +import { useLanguageGeneration } from '../i18n/useLanguageGeneration' import { useGuideRevealScope } from '../guide/GuideRevealScope' import { useGuideGate, useGuidePredicate } from '../guide/guidePredicates' import { appNavTarget } from '../appNav' @@ -158,6 +159,10 @@ const APP_LIST_RETURN_FLOOR_MS = 2000 function ShellTabTitle({ isChat, isPopout, panelLabel, instanceName, tabProduct, totalAttention, locationKey }: { isChat: boolean; isPopout: boolean; panelLabel: string; instanceName: string; tabProduct: string; totalAttention: number; locationKey: string }) { + // The language switch is subscribed to: a store-driven re-render that lands + // before the repaint would otherwise bail out, keeping the new labels but + // dropping the effects that hand them on. + useLanguageGeneration() // A slot whose title is its key or the backend placeholder has no real title // yet (same rule as the chat popout). const activeSessionTitle = useAppSelector(s => { diff --git a/website/src/test/App.tabTitle.test.tsx b/website/src/test/App.tabTitle.test.tsx index f14d9d3553a6..fe0e9c70f816 100644 --- a/website/src/test/App.tabTitle.test.tsx +++ b/website/src/test/App.tabTitle.test.tsx @@ -25,6 +25,8 @@ import { ThemeProvider } from '../hooks/useTheme' import { BrandingProvider } from '../hooks/useBranding' import type { ChatSlot } from '../types' import { namedCeiling } from './namedCeiling' +import { i18next } from '../i18n/all' +import { labelCurrentRouteEntry } from '../lib/routeHistoryLabels' // Counts shell renders: `useAppShell` runs once per render of the whole shell. const shellRenders = vi.hoisted(() => ({ count: 0 })) @@ -32,6 +34,11 @@ vi.mock('../shell/appShell', async (importOriginal) => { const actual = await importOriginal() return { ...actual, useAppShell: () => { shellRenders.count++; return actual.useAppShell() } } }) +// The real writer, watched: what the shell names the history entry on screen. +vi.mock('../lib/routeHistoryLabels', async (importOriginal) => { + const actual = await importOriginal() + return { ...actual, labelCurrentRouteEntry: vi.fn(actual.labelCurrentRouteEntry) } +}) vi.mock('../pages/ChatPage', () => ({ default: () =>
ChatPage
})) vi.mock('../pages/SchedulePage', () => ({ default: () =>
SchedulePage
})) vi.mock('../hooks/useWebSocket', () => ({ useWebSocket: () => ({ subscribeLogs: () => {}, subscribeSubagents: () => {}, forceReconnect: () => {} }) })) @@ -188,6 +195,25 @@ describe('main window tab title', () => { await waitFor(() => expect(document.title).toBe('Chat — Kiro Crew')) }) + it('names the tab and the history entry in the new language on the switch itself, with no repaint from above', async () => { + // A store-driven re-render that lands between the switch and the + // provider's repaint bails out, keeping the new label but dropping the + // effects that hand it on; following the switch itself closes that. + renderAt('/chat') + await waitFor(() => expect(document.title).toBe('Chat — Kiro Crew')) + await shellSettled() + expect(labelCurrentRouteEntry).toHaveBeenLastCalledWith('Chat') + try { + await act(async () => { await i18next.changeLanguage('ja') }) + const chat = i18next.t('app.tab_title_chat') + expect(chat).not.toBe('Chat') + expect(document.title).toBe(`${chat} — Kiro Crew`) + expect(labelCurrentRouteEntry).toHaveBeenLastCalledWith(chat) + } finally { + await act(async () => { await i18next.changeLanguage('en') }) + } + }) + it('names the panel on any other page', async () => { renderAt('/schedule') await waitFor(() => expect(document.title).toBe('Schedule — Kiro Crew')) diff --git a/website/src/test/AppPopoutFrame.test.tsx b/website/src/test/AppPopoutFrame.test.tsx index a454100f7791..ee1f953c6498 100644 --- a/website/src/test/AppPopoutFrame.test.tsx +++ b/website/src/test/AppPopoutFrame.test.tsx @@ -19,6 +19,7 @@ import { ThemeProvider } from '../hooks/useTheme' import { useAppDispatch } from '../store' import { setActiveSlot, setPendingInput, switchSlot } from '../store/chatSlice' import { ERROR_HANDOFF_KEY, consumeChatHandoff, handoffToChat, hardNavigate } from '../utils/errorReport' +import { i18next } from '../i18n/all' const popout = vi.hoisted(() => { const unregister = vi.fn() @@ -156,6 +157,7 @@ vi.mock('../apps/BuiltinAppRoute', async importOriginal => { } }) vi.mock('../pages/AppPage', () => ({ default: () =>
})) +vi.mock('../pages/ChannelPage', () => ({ default: () =>
})) import AppPopoutFrame, { AppPopoutHardExit, __resetForTests } from '../pages/AppPopoutFrame' @@ -295,6 +297,23 @@ describe('AppPopoutFrame', () => { expect(document.title).toBe('Dev Fleet — Kiro Crew') }) + it('re-titles a core page’s window on the language switch itself, with no repaint from above', async () => { + // A store-driven re-render that lands between the switch and the + // provider's repaint bails out, keeping the new label but dropping the + // effect that titles the window; following the switch itself closes that. + renderFrame('/channels', '/channels') + expect(document.title).toBe('Channels — Kiro Crew') + try { + await act(async () => { await i18next.changeLanguage('ja') }) + const label = i18next.t('nav.channels') + expect(label).not.toBe('Channels') + expect(document.title).toBe(`${label} — Kiro Crew`) + expect(screen.getByTestId('app-popout-title-bar')).toHaveTextContent(label) + } finally { + await act(async () => { await i18next.changeLanguage('en') }) + } + }) + it('lets the app navigate its own sub-paths in place', () => { renderFrame('/dev-fleet', '/dev-fleet') fireEvent.click(screen.getByRole('button', { name: 'deeper' }))