Skip to content

Commit 3330adb

Browse files
committed
fix(i18n): prevent infinite hmr loop
1 parent ac01921 commit 3330adb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"vite:build": "vite build",
3737
"vite:preview": "vite preview --host",
3838
"dev": "cross-env NODE_ENV=development run-p dist vite:serve",
39+
"dev:web": "VITE_SOURCEMAP=true VITE_WEB=true VITE_BASE=/trakt-extension/ run-s dev",
3940
"build": "cross-env NODE_ENV=production run-s dist type:check 'vite:build {@}' --",
4041
"build:web": "VITE_WEB=true VITE_BASE=/trakt-extension/ pnpm run build",
4142
"serve:web": "VITE_SOURCEMAP=true VITE_WEB=true VITE_BASE=/web-extension-template/ run-s build vite:preview",

src/utils/i18n.utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import { useI18nStore } from '~/stores/i18n.store';
44
import { useRouterStore } from '~/stores/router.store';
55
import { chromeI18n, useI18nTranslate } from '~/utils/browser/browser-i18n.utils';
66

7+
let promise: Promise<Locales | void> | undefined;
8+
let hotReload = false;
79
export const initLocalI18n = () => {
810
const store = useI18nStore();
911
const router = useRouterStore();
10-
let promise: Promise<Locales | void> | undefined;
12+
if (hotReload || promise) return { store, router, promise };
1113
if (import.meta.hot) {
1214
console.debug('Listening to i18n HMR changes');
1315
import.meta.hot.send('fetch:i18n');
1416
import.meta.hot.on('update:i18n', (data: { lang: string; locale: Locale }[]) => {
1517
data?.forEach(({ lang, locale }) => store.addLocale(locale, lang, true));
1618
});
19+
hotReload = true;
1720
} else if (!store.locales?.[store.lang]) {
1821
promise = fetch(new URL(`${router.baseUrl ?? './'}_locales/${store.lang}/messages.json`, new URL(import.meta.url).origin))
1922
.then(r => r.json())

0 commit comments

Comments
 (0)