Skip to content

fix(admin): use loadMessages in useLocale hook#504

Merged
ascorbic merged 3 commits intomainfrom
fix/admin-locale-client-resolution
Apr 12, 2026
Merged

fix(admin): use loadMessages in useLocale hook#504
ascorbic merged 3 commits intomainfrom
fix/admin-locale-client-resolution

Conversation

@ascorbic
Copy link
Copy Markdown
Collaborator

What does this PR do?

Follow-up to #499. The client-side locale switcher in useLocale.ts had 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

  • Bug fix

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code

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.
Copilot AI review requested due to automatic review settings April 12, 2026 22:01
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 12, 2026

🦋 Changeset detected

Latest commit: d49eab5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@emdash-cms/admin Patch
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/plugin-embeds Patch

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 12, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
🔵 In progress
View logs
emdash-playground d49eab5 Apr 12 2026, 10:10 PM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 12, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@504

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@504

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@504

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@504

emdash

npm i https://pkg.pr.new/emdash@504

create-emdash

npm i https://pkg.pr.new/create-emdash@504

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@504

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@504

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@504

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@504

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@504

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@504

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@504

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@504

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@504

commit: d49eab5

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 4 to +5
import { SUPPORTED_LOCALE_CODES } from "./config.js";
import { loadMessages } from "./index.js";
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

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

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 (indexuseLocale) 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.

Copilot uses AI. Check for mistakes.
Toggle buttons don't scale beyond a few locales. Use the kumo Select
dropdown instead. Add e2e tests for the language switcher.
@github-actions github-actions bot added size/M and removed size/XS labels Apr 12, 2026
@ascorbic ascorbic enabled auto-merge (squash) April 12, 2026 22:11
@ascorbic ascorbic merged commit e2f96aa into main Apr 12, 2026
29 checks passed
@ascorbic ascorbic deleted the fix/admin-locale-client-resolution branch April 12, 2026 22:17
@emdashbot emdashbot bot mentioned this pull request Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants