fix(metadata-admin): follow the live app locale, not just navigator.language - #2602
Merged
Conversation
…anguage Studio/metadata-admin screens resolved their locale via detectLocale() — a one-shot navigator.language read memoised per component — so they ignored the app language picked in the LocaleSwitcher. With the console on i18next 'en' and a zh browser, Studio rendered Chinese while the rest of the app was English (dogfood #2555: mixed-language session). Migrate every component call-site (20 files, ~40 sites) to the existing reactive useMetadataLocale() hook, which follows the live i18next language and re-renders on languageChanged: - Mechanical `React.useMemo(() => detectLocale(), [])` / bare detectLocale() → useMetadataLocale() across DirectoryPage, QuickFind, StudioHomePage, ResourceEditPage, ResourceListPage, PageShell, JsonSourceEditor, EmbeddedItemEditor, DiagnosticsPage, PackagesPage, PermissionMatrixEditor, ViewColumnPanes, PackageFormDialog, ViewConfigPanel, ReportConfigPanel, RuntimeDraftBar, widgets (×10). - SchemaForm: hook hoisted ABOVE the no-schema early return (stable hook order); SectionedSchemaForm/RepeaterField hoist one hook each for their inline t()/tFormat() calls; issuesByPath memo deps now [issues, locale]. - AssignedUsersSection: the zh copy flag is now reactive (=== 'zh-CN'); its copy memo already depended on [zh]. - detectLocale() stays exported as a non-hook fallback, with a JSDoc pointer to useMetadataLocale. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
…llow-app-locale # Conflicts: # packages/app-shell/src/views/metadata-admin/PermissionMatrixEditor.tsx
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Studio/metadata-admin screens resolved their locale with
detectLocale()— a one-shotnavigator.languageread memoised per component — so they ignored the app language picked in the LocaleSwitcher. A session with the console on English + a Chinese browser rendered Studio in Chinese while the rest of the app was English. Mixed-language item of the dogfood follow-ups in #2555.Change
Migrate every component call-site (20 files, ~40 sites) from
detectLocale()to the existing reactiveuseMetadataLocale()hook, which follows the live i18next language (viauseObjectTranslation()) and re-renders onlanguageChanged.React.useMemo(() => detectLocale(), [])/ baredetectLocale()at component tops → hook).SchemaForm.tsx: hook hoisted above the no-schema early return (stable hook order — the pre-existinguseMemoafter that return was fragile);SectionedSchemaForm/RepeaterFieldhoist one hook each for their inlinet()/tFormat()calls;issuesByPathmemo deps now[issues, locale].AssignedUsersSection: thezhcopy flag is now reactive (useMetadataLocale() === 'zh-CN'); its copy memo already depended on[zh].detectLocale()stays exported as a non-hook fallback with a JSDoc pointer to the hook.No visible change when the app language already matches the browser; the fix is that switching the app language (or having them differ) now updates Studio in place instead of staying on
navigator.language.Verification
detectLocale(call-sites outsidei18n.ts(grep).@object-ui/*/ implicit-any cascade, which CI resolves by building packages first).studio-locale.i18n.test.tsx(F1 — including flips in place when the active language is switched at runtime),PackageFormDialog,EditPackageDialog,CreatePackageDialog.namespace,PackageIdInput.Closes the mixed-language item of #2555.
🤖 Generated with Claude Code