From 42f7d549a09e66a4bebd2d9a21a351d9329a591e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 2 May 2023 22:40:57 +0100 Subject: [PATCH 1/7] fix(nuxt): allow resolving client nuxt app to singleton --- packages/nuxt/src/app/entry.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index 19a6d3b6a209..249d87d600ea 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -54,6 +54,7 @@ if (process.client) { } entry = async function initApp () { + if (app) { return app } const isSSR = Boolean( window.__NUXT__?.serverRendered || document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true' @@ -81,7 +82,7 @@ if (process.client) { } } - entry().catch((error: unknown) => { + const app = entry().catch((error: unknown) => { console.error('Error while mounting app:', error) }) } From dfcc22932f911db8a0992013efd55033c342c9dc Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 21:44:32 +0000 Subject: [PATCH 2/7] [autofix.ci] apply automated fixes --- test/bundle.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 9c5fb0586848..a0ba45f5fcbf 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.0k"') + expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.1k"') expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(` [ "_nuxt/entry.js", From 827354d629785224b53fe83f20423e52879a4bdd Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 2 May 2023 22:55:13 +0100 Subject: [PATCH 3/7] fix: initialise app --- packages/nuxt/src/app/entry.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index 249d87d600ea..b0fcd551a980 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -53,6 +53,9 @@ if (process.client) { import.meta.webpackHot.accept() } + // eslint-disable-next-line + let app: Promise + entry = async function initApp () { if (app) { return app } const isSSR = Boolean( @@ -82,7 +85,7 @@ if (process.client) { } } - const app = entry().catch((error: unknown) => { + app = entry().catch((error: unknown) => { console.error('Error while mounting app:', error) }) } From 8f86654eedadc5f288eadb6b394930dcf84ec811 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 2 May 2023 23:06:45 +0100 Subject: [PATCH 4/7] feat: return vueApp from init --- packages/nuxt/src/app/entry.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index b0fcd551a980..107cbe0ac93a 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -83,6 +83,8 @@ if (process.client) { await nuxt.callHook('app:error', err) nuxt.payload.error = (nuxt.payload.error || err) as any } + + return vueApp } app = entry().catch((error: unknown) => { From d51cbf71613f11c63f2f515c698cdec89ce3d1c3 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 3 May 2023 21:55:02 +0100 Subject: [PATCH 5/7] refactor: rename to `vueAppPromise` --- packages/nuxt/src/app/entry.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index 107cbe0ac93a..db77ed4823ee 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -54,10 +54,10 @@ if (process.client) { } // eslint-disable-next-line - let app: Promise + let vueAppPromise: Promise entry = async function initApp () { - if (app) { return app } + if (vueAppPromise) { return vueAppPromise } const isSSR = Boolean( window.__NUXT__?.serverRendered || document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true' @@ -87,7 +87,7 @@ if (process.client) { return vueApp } - app = entry().catch((error: unknown) => { + vueAppPromise = entry().catch((error: unknown) => { console.error('Error while mounting app:', error) }) } From 786a16365de8faebd2a00196552ab9b7e2b9c78f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 3 May 2023 21:56:13 +0100 Subject: [PATCH 6/7] test: update bundle --- test/bundle.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 3dcc7c8e17f5..b2a0d6c79d79 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", @@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e it('default server bundle size', async () => { stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.7k"') + expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.6k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2654k"') From c4ae9a2a1ccab666f71f213c1172d9df823f8e37 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 3 May 2023 20:58:08 +0000 Subject: [PATCH 7/7] [autofix.ci] apply automated fixes --- test/bundle.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bundle.test.ts b/test/bundle.test.ts index b2a0d6c79d79..54c39f913d84 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e it('default server bundle size', async () => { stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.6k"') + expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.7k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2654k"')