From a352d59a582164e05a6afe3dd580c79eabc43970 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 25 Aug 2023 13:26:23 +0100 Subject: [PATCH] fix(nuxt): default `spaLoadingTemplate` to `false` (#22798) --- packages/nuxt/src/core/nitro.ts | 6 ++++-- packages/schema/src/config/app.ts | 4 ++-- test/bundle.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 917df7dc35..73a7a83377 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -31,7 +31,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { : [/node_modules/] const spaLoadingTemplate = nuxt.options.spaLoadingTemplate ?? resolve(nuxt.options.srcDir, 'app/spa-loading-template.html') - if (spaLoadingTemplate && nuxt.options.spaLoadingTemplate && !existsSync(spaLoadingTemplate)) { + if (spaLoadingTemplate && nuxt.options.spaLoadingTemplate && typeof spaLoadingTemplate !== 'boolean' && !existsSync(spaLoadingTemplate)) { console.warn(`[nuxt] Could not load custom \`spaLoadingTemplate\` path as it does not exist: \`${spaLoadingTemplate}\`.`) } @@ -89,7 +89,9 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { '#spa-template': () => { if (!spaLoadingTemplate) { return 'export const template = ""' } try { - return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}` + if (spaLoadingTemplate !== true) { + return `export const template = ${JSON.stringify(readFileSync(spaLoadingTemplate, 'utf-8'))}` + } } catch {} return `export const template = ${JSON.stringify(defaultSpaLoadingTemplate({}))}` } diff --git a/packages/schema/src/config/app.ts b/packages/schema/src/config/app.ts index af468b54b0..d7b75d1523 100644 --- a/packages/schema/src/config/app.ts +++ b/packages/schema/src/config/app.ts @@ -241,10 +241,10 @@ export default defineUntypedSchema({ * } * * ``` - * @type {string | false} + * @type {string | boolean} */ spaLoadingTemplate: { - $resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : (val ?? null) + $resolve: async (val, get) => typeof val === 'string' ? resolve(await get('srcDir'), val) : (val ?? false) }, /** diff --git a/test/bundle.test.ts b/test/bundle.test.ts index 33668ab4c6..f1005e216e 100644 --- a/test/bundle.test.ts +++ b/test/bundle.test.ts @@ -32,7 +32,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"298k"') + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"297k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"1822k"') @@ -71,7 +71,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM const serverDir = join(rootDir, '.output-inline/server') const serverStats = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) - expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"604k"') + expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"603k"') const modules = await analyzeSizes('node_modules/**/*', serverDir) expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"70.5k"')