Skip to content

Commit a2a3a73

Browse files
authored
improvement: tweak vue-i18n for SSR (#929)
1 parent ede3da6 commit a2a3a73

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

packages/vue-i18n-core/src/composer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
isBoolean,
1111
isPlainObject,
1212
isObject,
13-
assign
13+
assign,
14+
inBrowser
1415
} from '@intlify/shared'
1516
import {
1617
isTranslateFallbackWarn,
@@ -2346,7 +2347,7 @@ export function createComposer(options: any = {}, VueI18nLegacy?: any): any {
23462347
composerID++
23472348

23482349
// watch root locale & fallbackLocale
2349-
if (__root) {
2350+
if (__root && inBrowser) {
23502351
watch(__root.locale, (val: Locale) => {
23512352
if (_inheritLocale) {
23522353
_locale.value = val

packages/vue-i18n-core/src/i18n.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isRef
99
} from 'vue'
1010
import {
11+
inBrowser,
1112
isEmptyObject,
1213
isBoolean,
1314
warn,
@@ -929,9 +930,13 @@ function setupLifeCycle(
929930
}
930931
vm._i18n = _i18n
931932
vm._i18n_bridge = true
932-
vm._i18nWatcher = vm._i18n.watchI18nData()
933-
if (vm._i18n._sync) {
934-
vm._localeWatcher = vm._i18n.watchLocale()
933+
934+
// browser only
935+
if (inBrowser) {
936+
vm._i18nWatcher = vm._i18n.watchI18nData()
937+
if (vm._i18n._sync) {
938+
vm._localeWatcher = vm._i18n.watchLocale()
939+
}
935940
}
936941

937942
let subscribing = false

packages/vue-i18n-core/test/composer.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
14
/* eslint-disable @typescript-eslint/no-empty-function, @typescript-eslint/no-explicit-any */
25

36
// utils

0 commit comments

Comments
 (0)