Skip to content

Commit

Permalink
fix(nuxt): allow resolving client nuxt app to singleton (nuxt#20639)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored May 9, 2023
1 parent ddbb847 commit 1da25c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/nuxt/src/app/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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) => {
vueAppPromise = entry().catch((error: unknown) => {
console.error('Error while mounting app:', error)
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Original file line number Diff line number Diff line change
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.1k"')
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.2k"')
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
[
"_nuxt/entry.js",
Expand Down

0 comments on commit 1da25c8

Please sign in to comment.