Repository navigation
perf(client): load locale messages on demand #1160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,13 @@ | ||
| import { watch } from 'vue' | ||
| import { defineNuxtPlugin } from '#imports' | ||
| import { useDevToolsLocale } from '../composables/locale' | ||
| import { i18n } from '../i18n' | ||
| import { i18n, setLocale } from '../i18n' | ||
|
|
||
| export default defineNuxtPlugin((nuxtApp) => { | ||
| export default defineNuxtPlugin(async (nuxtApp) => { | ||
| nuxtApp.vueApp.use(i18n) | ||
|
|
||
| const locale = useDevToolsLocale() | ||
| watch(locale, (value) => { | ||
| i18n.global.locale.value = value | ||
| if (typeof document !== 'undefined') | ||
| document.documentElement.lang = value | ||
| }, { immediate: true }) | ||
| // Load the initial locale before the first render to avoid an English flash. | ||
| await setLocale(locale.value) | ||
| watch(locale, value => setLocale(value)) | ||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: nuxt/devtools
Length of output: 1403
Script executed:
Repository: nuxt/devtools
Length of output: 9066
Web query:
Nuxt 3 client plugins async defineNuxtPlugin await before app mount applyPlugins vueApp.mount documentationResult:
Script executed:
Repository: nuxt/devtools
Length of output: 584
Add a deadline to the initial locale load.
The plugin awaits
setLocale(locale.value), and Nuxt does not mount the client until app plugins finish. If a non-English locale chunk stays pending, the DevTools UI stays blank. Race the initial load against a timeout, then mount with English until the chunk resolves.