Skip to content
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

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

Merged
merged 9 commits into from May 9, 2023
8 changes: 7 additions & 1 deletion packages/nuxt/src/app/entry.ts
Expand Up @@ -53,7 +53,11 @@ if (process.client) {
import.meta.webpackHot.accept()
}

// eslint-disable-next-line
let app: Promise<any>
danielroe marked this conversation as resolved.
Show resolved Hide resolved

entry = async function initApp () {
if (app) { return app }
const isSSR = Boolean(
window.__NUXT__?.serverRendered ||
document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true'
Expand All @@ -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) => {
app = entry().catch((error: unknown) => {
console.error('Error while mounting app:', error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Expand Up @@ -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",
Expand Down