fix(admin): use loadMessages in useLocale hook#504
Conversation
The client-side locale switcher had the same dynamic import issue —
raw `import(./${code}/messages.mjs)` fails when resolved through
Vite aliases. Reuse the glob-based loadMessages from index.ts.
🦋 Changeset detectedLatest commit: d49eab5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| 🔵 In progress View logs |
emdash-playground | d49eab5 | Apr 12 2026, 10:10 PM |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
Pull request overview
Fixes client-side locale switching in the admin useLocale hook by replacing a runtime dynamic import (problematic with Vite alias resolution in the browser) with the existing glob-based locale loader introduced in #499.
Changes:
- Replace
import(\./${code}/messages.mjs`)withloadMessages(code)` when switching locales. - Keep cookie-based persistence while loading/activating the new locale catalog via Lingui.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { SUPPORTED_LOCALE_CODES } from "./config.js"; | ||
| import { loadMessages } from "./index.js"; |
There was a problem hiding this comment.
useLocale.ts now imports loadMessages from the ./index.js barrel, but index.ts also re-exports useLocale (see packages/admin/src/locales/index.ts:5). This introduces a circular dependency (index ↔ useLocale) which can be fragile and may cause subtle initialization/order issues as the module grows.
Consider moving loadMessages into its own module (e.g. loadMessages.ts) and importing it directly from there (and re-exporting from index.ts), or importing it from that new module here to avoid the cycle.
Toggle buttons don't scale beyond a few locales. Use the kumo Select dropdown instead. Add e2e tests for the language switcher.
What does this PR do?
Follow-up to #499. The client-side locale switcher in
useLocale.tshad the same dynamic import issue —import(\./${code}/messages.mjs`)fails at runtime in the browser when resolved through Vite aliases. Reuses the glob-basedloadMessages` from the fix in #499.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runpnpm locale:extracthas been run (if applicable)AI-generated code disclosure