From 020f212114c594c7b7c2d082940a8ebe2b53ef4d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 27 Nov 2024 14:14:53 +0000 Subject: [PATCH] refactor: rename to `spaLoadingTemplateLocation` --- packages/nuxt/src/app/entry.ts | 4 ++-- packages/nuxt/src/core/runtime/nitro/renderer.ts | 4 ++-- packages/nuxt/src/core/templates.ts | 2 +- packages/schema/src/config/experimental.ts | 5 +++-- test/fixtures/spa-loader/nuxt.config.ts | 2 +- test/spa-loader/spa-preloader-outside-disabled.test.ts | 4 ++-- test/spa-loader/spa-preloader-outside-enabled.test.ts | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index 8c782f5147..2e9ac9e80c 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -17,7 +17,7 @@ import plugins from '#build/plugins' // @ts-expect-error virtual file import RootComponent from '#build/root-component.mjs' // @ts-expect-error virtual file -import { appId, appSpaLoaderAttrs, multiApp, spaPreloaderOutside, vueAppRootContainer } from '#build/nuxt.config.mjs' +import { appId, appSpaLoaderAttrs, multiApp, spaLoadingTemplateOutside, vueAppRootContainer } from '#build/nuxt.config.mjs' let entry: (ssrContext?: CreateOptions['ssrContext']) => Promise> @@ -72,7 +72,7 @@ if (import.meta.client) { if (vueApp.config.errorHandler === handleVueError) { vueApp.config.errorHandler = undefined } }) - if (spaPreloaderOutside && !isSSR && appSpaLoaderAttrs.id) { + if (spaLoadingTemplateOutside && !isSSR && appSpaLoaderAttrs.id) { // Remove spa loader if present nuxt.hook('app:suspense:resolve', () => { document.getElementById(appSpaLoaderAttrs.id)?.remove() diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 431adf9c92..428bef8578 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -30,7 +30,7 @@ import { renderSSRHeadOptions } from '#internal/unhead.config.mjs' import type { NuxtPayload, NuxtSSRContext } from '#app' // @ts-expect-error virtual file -import { appHead, appId, appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, appTeleportAttrs, appTeleportTag, componentIslands, multiApp, spaPreloaderOutside } from '#internal/nuxt.config.mjs' +import { appHead, appId, appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, appTeleportAttrs, appTeleportTag, componentIslands, multiApp, spaLoadingTemplateOutside } from '#internal/nuxt.config.mjs' // @ts-expect-error virtual file import { buildAssetsURL, publicAssetsURL } from '#internal/nuxt/paths' @@ -145,7 +145,7 @@ const getSPARenderer = lazyCachedFunction(async () => { // @ts-expect-error virtual file const spaTemplate = await import('#spa-template').then(r => r.template).catch(() => '') .then((r) => { - if (spaPreloaderOutside) { + if (spaLoadingTemplateOutside) { const APP_SPA_LOADER_OPEN_TAG = `<${appSpaLoaderTag}${propsToString(appSpaLoaderAttrs)}>` const APP_SPA_LOADER_CLOSE_TAG = `` const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 1b44154291..2abe6e0705 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -525,7 +525,7 @@ export const nuxtConfigTemplate: NuxtTemplate = { `export const multiApp = ${!!ctx.nuxt.options.future.multiApp}`, `export const chunkErrorEvent = ${ctx.nuxt.options.experimental.emitRouteChunkError ? ctx.nuxt.options.builder === '@nuxt/vite-builder' ? '"vite:preloadError"' : '"nuxt:preloadError"' : 'false'}`, `export const crawlLinks = ${!!((ctx.nuxt as any)._nitro as Nitro).options.prerender.crawlLinks}`, - `export const spaPreloaderOutside = ${ctx.nuxt.options.experimental.spaPreloaderOutside}`, + `export const spaLoadingTemplateOutside = ${ctx.nuxt.options.experimental.spaLoadingTemplateLocation === 'body'}`, ].join('\n\n') }, } diff --git a/packages/schema/src/config/experimental.ts b/packages/schema/src/config/experimental.ts index 6393bea03d..f2af197d35 100644 --- a/packages/schema/src/config/experimental.ts +++ b/packages/schema/src/config/experimental.ts @@ -411,10 +411,11 @@ export default defineUntypedSchema({ /** * Keep showing the spa-loading-template until suspense:resolve * @see [Nuxt Issues #24770](https://github.com/nuxt/nuxt/issues/21721) + * @type {'body' | 'within'} */ - spaPreloaderOutside: { + spaLoadingTemplateLocation: { $resolve: async (val, get) => { - return val ?? ((await get('future') as Record).compatibilityVersion === 4) + return val ?? (((await get('future') as Record).compatibilityVersion === 4) ? 'body' : 'within') }, }, }, diff --git a/test/fixtures/spa-loader/nuxt.config.ts b/test/fixtures/spa-loader/nuxt.config.ts index e40b0471eb..06849bbb95 100644 --- a/test/fixtures/spa-loader/nuxt.config.ts +++ b/test/fixtures/spa-loader/nuxt.config.ts @@ -6,7 +6,7 @@ export default defineNuxtConfig({ '/ssr': { ssr: true }, }, experimental: { - spaPreloaderOutside: false, + spaLoadingTemplateLocation: 'within', }, compatibilityDate: '2024-06-28', }) diff --git a/test/spa-loader/spa-preloader-outside-disabled.test.ts b/test/spa-loader/spa-preloader-outside-disabled.test.ts index 83259d0ba5..d23cf4773d 100644 --- a/test/spa-loader/spa-preloader-outside-disabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-disabled.test.ts @@ -17,12 +17,12 @@ await setup({ builder: isWebpack ? 'webpack' : 'vite', spaLoadingTemplate: true, experimental: { - spaPreloaderOutside: false, + spaLoadingTemplateLocation: 'within', }, }, }) -describe('spaPreloaderOutside flag is disabled', () => { +describe('spaLoadingTemplateLocation flag is set to `within`', () => { it('shoul be render loader inside appTag', async () => { const html = await $fetch('/spa') expect(html).toContain(`
loading...
\n
`) diff --git a/test/spa-loader/spa-preloader-outside-enabled.test.ts b/test/spa-loader/spa-preloader-outside-enabled.test.ts index 71c873bd74..18367707b8 100644 --- a/test/spa-loader/spa-preloader-outside-enabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-enabled.test.ts @@ -15,12 +15,12 @@ await setup({ builder: isWebpack ? 'webpack' : 'vite', spaLoadingTemplate: true, experimental: { - spaPreloaderOutside: true, + spaLoadingTemplateLocation: 'body', }, }, }) -describe('spaPreloaderOutside flag is enabled', () => { +describe('spaLoadingTemplateLocation flag is set to `body`', () => { it('should render spa-loader', async () => { const browser = await getBrowser() const page = await browser.newPage({})