diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index 19a6d3b6a209..db77ed4823ee 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -53,7 +53,11 @@ if (process.client) { import.meta.webpackHot.accept() } + // eslint-disable-next-line + let vueAppPromise: Promise + 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) }) } diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 3319dfa19270..65db0e75204e 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -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",