fix(nuxt): allow resolving client nuxt app to singleton (#20639)

This commit is contained in:
Daniel Roe 2023-05-09 11:22:38 +01:00 committed by GitHub
parent ddbb847979
commit 1da25c8069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -53,7 +53,11 @@ if (process.client) {
import.meta.webpackHot.accept()
}
// eslint-disable-next-line
let vueAppPromise: Promise<any>
entry = async function initApp () {
if (vueAppPromise) { return vueAppPromise }
const isSSR = Boolean(
window.__NUXT__?.serverRendered ||
document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true'
@ -79,9 +83,11 @@ if (process.client) {
await nuxt.callHook('app:error', err)
nuxt.payload.error = (nuxt.payload.error || err) as any
}
return vueApp
}
entry().catch((error: unknown) => {
vueAppPromise = entry().catch((error: unknown) => {
console.error('Error while mounting app:', error)
})
}

View File

@ -34,7 +34,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
it('default client bundle size', async () => {
stats.client = await analyzeSizes('**/*.js', publicDir)
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.1k"')
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.2k"')
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
[
"_nuxt/entry.js",