From 10781da08650214893bc746bbce74956832888dc Mon Sep 17 00:00:00 2001 From: gitlawr Date: Tue, 12 May 2026 12:00:22 +0800 Subject: [PATCH] fix: plugin locale merge re-runs on HMR; API Key form allows Personal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - locale-merger: drop the module-level dedup Set. addLocale is idempotent, and the guard made HMR-added plugin locale keys silently skipped — strings like organizations.members.selectUsers stayed unresolved until a full dev-server restart. - api-keys form: pass allowPersonal: true to CreateOrgScopeField so admin in Platform-wide mode can target their own Personal Org when creating a key (unlike infra resources where Personal doesn't fit). --- .../components/add-apikey-modal/form.tsx | 5 ++++- src/plugins/locale-merger.ts | 21 +++++++------------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pages/api-keys/components/add-apikey-modal/form.tsx b/src/pages/api-keys/components/add-apikey-modal/form.tsx index 9f905b8a..911203a7 100644 --- a/src/pages/api-keys/components/add-apikey-modal/form.tsx +++ b/src/pages/api-keys/components/add-apikey-modal/form.tsx @@ -45,7 +45,10 @@ const APIKeyForm: React.FC<{ > - + name="expires_in" diff --git a/src/plugins/locale-merger.ts b/src/plugins/locale-merger.ts index 71a1450d..6dcc28fd 100644 --- a/src/plugins/locale-merger.ts +++ b/src/plugins/locale-merger.ts @@ -1,32 +1,27 @@ import { addLocale } from '@umijs/max'; -const mergedLocales = new Set(); - /** - * Merge enterprise plugin locales into the main application + * Merge enterprise plugin locales into the main application. + * + * `addLocale` is idempotent: re-calling with the latest message dict + * overwrites previous entries, so we always pass the freshest plugin + * locales through. A previous version deduped via a module-level Set + * and that broke HMR — newly added keys in plugin locale files were + * skipped on the second merge, leaving the placeholder/validation + * strings unresolved until a full server restart. */ export function mergeEnterpriseLocales(locales: Record = {}) { if (!locales) { return; } - console.log('Merging enterprise plugin locales:', Object.keys(locales)); - - // Iterate over all locale configurations of the enterprise plugin Object.entries(locales).forEach(([locale, messages]) => { try { - if (mergedLocales.has(locale)) { - return; - } - - // Merge the enterprise locale into the main application addLocale(locale, messages, { momentLocale: '', // @ts-ignore antd: locale }); - mergedLocales.add(locale); - console.log(`✓ Merged enterprise locale: ${locale}`, messages); } catch (error) { console.error(`Failed to merge enterprise locale ${locale}:`, error); }