Repository navigation
fix(i18n): re-render memoized translated UI on language changes - #35358
Conversation
…hanges Memoized components and useMemo/module caches that call translate() kept the previous language after a switch or a plugin language-pack reload, because react-i18next only re-renders components that subscribe themselves. Add useUiLanguageRevision() (language + catalog revision via useSyncExternalStore), call it in the 34 memoized translating components, key translated useMemo results and module caches on it, and add a ratchet so new memoized translating components must subscribe. Fixes the composer pickers reported in #34783. Co-authored-by: Vyacheslav Scherbinin <14369958+gentslava@users.noreply.github.com>
[High impact] The PR appears safe to merge; the remaining test coverage concern is non-blocking. Findings
SummaryMakes translated menus, rows, and dialogs redraw when the language or a language pack changes.
|
| await act(() => i18n.changeLanguage('fr')) | ||
|
|
||
| expect(screen.getByText('Demander l’approbation')).toBeTruthy() | ||
| expect(screen.getByRole('button', { name: /^Modèle Opus/ })).toBeTruthy() |
There was a problem hiding this comment.
Pack refreshes lack render coverage
This test only changes the language. It does not check whether mounted components redraw when a language pack changes without changing i18n.language. Existing catalog tests call getters directly, so they would still pass if the hook stopped subscribing to resource changes.
Add a mounted-component test that replaces and removes the active pack while keeping props and language fixed, then checks the displayed labels.
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Minor · Refresh the accessible label on language changes. · branch-line-total-chip.tsx:142
src/renderer/src/components/right-sidebar/source-control/panel/branch-line-total-chip.tsx:142
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winRefresh the accessible label on language changes.
When only the language or translation resources change,
splitRowsrefreshes, butaccessibleLabelretains its previous translation. The chip then announces an old-language label to screen-reader users. AddlanguageRevisionto theaccessibleLabelmemo dependencies. (raw.githubusercontent.com)

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
12435999-6bd9-4ec1-a1c0-9c3342f2f022
Files selected for processing: 62-
config/memo-translate-subscription-baseline.txtconfig/scripts/check-memo-translate-subscription-ratchet.mjsconfig/scripts/check-memo-translate-subscription-ratchet.test.mjspackage.jsonsrc/renderer/src/components/activity/activity-standalone-worktree.tssrc/renderer/src/components/activity/activity-thread-row.tsxsrc/renderer/src/components/automations/AutomationRunsDashboard.tsxsrc/renderer/src/components/browser-pane/annotate/MarkupToolbar.tsxsrc/renderer/src/components/cmd-j/PaletteFilterMenu.tsxsrc/renderer/src/components/editor/DiffNotesSendMenu.tsxsrc/renderer/src/components/editor/VirtualMarkdownPreviewBody.tsxsrc/renderer/src/components/editor/rich-markdown-code-block-languages.tssrc/renderer/src/components/editor/use-markdown-preview-foundation.tssrc/renderer/src/components/editor/useRichMarkdownReviewData.tssrc/renderer/src/components/floating-terminal/FloatingTerminalIconContextMenu.tsxsrc/renderer/src/components/github-item-dialog/edit-item-fields/gh-edit-section.tsxsrc/renderer/src/components/jira-user-picker.tsxsrc/renderer/src/components/native-chat/NativeChatAutocompleteMenus.tsxsrc/renderer/src/components/native-chat/NativeChatMessageRail.tsxsrc/renderer/src/components/native-chat/NativeChatPermissionModePicker.tsxsrc/renderer/src/components/native-chat/NativeChatQueuedMessageRows.tsxsrc/renderer/src/components/native-chat/NativeChatSessionOptionPickers.tsxsrc/renderer/src/components/native-chat/native-chat-pickers-language-switch.test.tsxsrc/renderer/src/components/native-chat/use-native-chat-launch-prompt-delivery-notice.tssrc/renderer/src/components/native-chat/use-native-chat-pending-delivery.tssrc/renderer/src/components/right-sidebar/FileExplorer.tsxsrc/renderer/src/components/right-sidebar/HostedReviewActions.tsxsrc/renderer/src/components/right-sidebar/index.tsxsrc/renderer/src/components/right-sidebar/source-control/ai/text-generation-dialog.tsxsrc/renderer/src/components/right-sidebar/source-control/commit/recovery-notice.tsxsrc/renderer/src/components/right-sidebar/source-control/listing/uncommitted-entry-row.tsxsrc/renderer/src/components/right-sidebar/source-control/panel/branch-line-total-chip.tsxsrc/renderer/src/components/right-sidebar/source-control/review/use-action-model.tssrc/renderer/src/components/right-sidebar/use-right-sidebar-activity-items.tssrc/renderer/src/components/settings/BrowserPane.tsxsrc/renderer/src/components/settings/MobileEmulatorSettingsPane.tsxsrc/renderer/src/components/settings/VoiceMicrophoneSetting.tsxsrc/renderer/src/components/sidebar/AddProjectFromFolderDialog.tsxsrc/renderer/src/components/sidebar/DeleteWorktreeDialog.tsxsrc/renderer/src/components/sidebar/NonGitFolderDialog.tsxsrc/renderer/src/components/sidebar/OrcaYamlTrustDialog.tsxsrc/renderer/src/components/sidebar/RemoveFolderDialog.tsxsrc/renderer/src/components/sidebar/SetupScriptPromptCard.tsxsrc/renderer/src/components/sidebar/SidebarFilter.tsxsrc/renderer/src/components/sidebar/SidebarRepositoryFilterSection.tsxsrc/renderer/src/components/sidebar/SidebarWorkspaceOptionsMenu.tsxsrc/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsxsrc/renderer/src/components/sidebar/WorkspaceKanbanCard.tsxsrc/renderer/src/components/sidebar/WorkspaceKanbanStatusLane.tsxsrc/renderer/src/components/sidebar/WorktreeCardAgents.tsxsrc/renderer/src/components/sidebar/WorktreeMetaDialogDraft.tsxsrc/renderer/src/components/sidebar/WorktreeParentPickerRow.tsxsrc/renderer/src/components/sidebar/worktree-list/viewport/VirtualizedWorktreeViewport.tsxsrc/renderer/src/components/status-bar/PetStatusSegment.tsxsrc/renderer/src/components/status-bar/ResourcePtyRow.tsxsrc/renderer/src/components/status-bar/use-owner-usage-rate-limits.tssrc/renderer/src/components/tab-bar/QuickLaunchButton.tsxsrc/renderer/src/components/use-worktree-jump-palette-list-entries.tssrc/renderer/src/components/workspace-cleanup/workspace-cleanup-candidate-row.tsxsrc/renderer/src/hooks/useSettingsNavigationMetadata.tssrc/renderer/src/i18n/translation-resource-version.tssrc/renderer/src/i18n/use-ui-language-revision.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
-
| const COMMENT = /\/\*[\s\S]*?\*\/|(?<![:'"`\\])\/\/.*$/gm | ||
| const TRANSLATE_CALL = /\btranslate\(/ | ||
| const SUBSCRIPTION_CALL = /\b(?:useUiLanguageRevision|useTranslation)\(/ | ||
| const MEMO_CALL = /\b(?:React\.)?memo\(\s*(?:function\s+([\w$]+)|([\w$]+)\s*[,)])/g |
There was a problem hiding this comment.
Detect arrow and anonymous memo components.
If a component uses const Row = memo(() => <span>{translate('k', 'Row')}</span>), MEMO_CALL finds no match. The ratchet then passes even though Row does not subscribe and can retain its old label after a language change. Recognize these memo arguments, derive the component name from the binding, and add regression cases. (raw.githubusercontent.com)
| remoteStatus, | ||
| unresolvedConflictCount | ||
| unresolvedConflictCount, | ||
| languageRevision |
There was a problem hiding this comment.
Invalidate every translated action memo.
When the language changes without a source-control input change, only createPrHeaderAction recomputes. resolveCommitAreaPrimaryAction and resolveDropdownItems also produce translated labels and titles, but their memos retain the old text. Add languageRevision to both the primaryAction and dropdownItems dependency arrays. (raw.githubusercontent.com)
Tests that mock @/i18n/i18n have no i18n instance, so subscribe through translation-resource-version (now also bumped on languageChanged) and give useSyncExternalStore a server snapshot for renderToString tests.
ELI5
When you switch Orca's UI language, some menus, rows and dialogs kept showing the old language until something else made them redraw. This makes them redraw as soon as the language (or a language pack) changes.
What Changed
useUiLanguageRevision()hook (src/renderer/src/i18n/use-ui-language-revision.ts): auseSyncExternalStoresubscription to the existing translation-resource version, which now notifies listeners and also advances on i18nextlanguageChanged(one line ini18n.ts), so it covers language switches and catalog or plugin language-pack reloads.memo()components that calltranslate()without their own subscription now call the hook.memoblocks the parent re-render a language switch relies on, and react-i18next only re-renders components that subscribe themselves. This includes the composer model/effort and permission pickers from [Bug]: Preserve remaining source-language fixes after Russian locale extraction #34783 and the right sidebar activity bar.useMemoresults that hold translated text (21 sites, e.g. right sidebar activity items, floating terminal menu, settings panes, source control action model) now list the revision as a dependency.useSettingsNavigationMetadatakeys on it instead ofi18n.language, so a reloaded plugin pack also refreshes. The standalone activity worktree cache and the code block language list use the language + resource version (createLocalizedCatalog) instead of the language or bundle identity alone.check-memo-translate-subscriptionratchet: a memoized component in a file that callstranslate()must subscribe. Two grandfathered entries render no translated text.Why
One mechanism instead of sprinkling
useTranslation()calls: it covers plugin language-pack reloads (same language, new resources), works in plain hooks, and the ratchet keeps new memoized components from regressing.Linked Issue
Refs #34783 (the picker cases), Refs #32207
Visual Proof
N/A: no visual change in a single language; the fix only affects re-rendering after a language switch, covered by the test below.
Testing
native-chat-pickers-language-switch.test.tsx: renders the memoized permission and session option pickers with fixed props, switches to French, and asserts both relabel (fails without the hook).pnpm tc:web; lint with--deny-warnings; affected tests viapnpm check:changed.Picker fix credit: @gentslava (#33370).