fix(webui): keep every concurrently loaded channel locale registered
loadChannelLocale() captured the per-channel translation map before awaiting the locale loader and re-registered it afterwards. Because initializeI18n() loads the fallback and initial locales concurrently, two calls per channel each created their own Map and the one resolving last replaced the other's registration, silently dropping one locale from every channel for any user whose stored locale is not en. Create and register the map synchronously, before any await, so concurrent loads append to a single shared Map. Add a regression test that loads two locales concurrently against a fresh registry instance.
This commit is contained in:
1 parent
3d40ed8f76
commit
8fb7bc34ec
2 files changed
+31
-3
No files matched your search
@@ -73,7 +73,13 @@ async function loadChannelLocale(
|
||||
channel: string,
|
||||
locale: SupportedLocale,
|
||||
): Promise<ChannelMessages> {
|
||||
const translations = translationsByChannel.get(channel) ?? new Map();
|
||||
// Get-or-create the shared per-channel map synchronously so concurrent locale
|
||||
// loads append to one Map instead of replacing each other's registration.
|
||||
let translations = translationsByChannel.get(channel);
|
||||
if (!translations) {
|
||||
translations = new Map();
|
||||
translationsByChannel.set(channel, translations);
|
||||
}
|
||||
const loaded = translations.get(locale);
|
||||
if (loaded) return loaded;
|
||||
|
||||
@@ -87,6 +93,5 @@ async function loadChannelLocale(
|
||||
throw new Error(`Channel '${channel}' locale '${locale}' has no default export`);
|
||||
}
|
||||
translations.set(locale, messages);
|
||||
translationsByChannel.set(channel, translations);
|
||||
return messages;
|
||||
}
|
||||
Reference in new issue
Block a user