refactor: rename to spaLoadingTemplateLocation

This commit is contained in:
Daniel Roe 2024-11-27 14:14:53 +00:00
parent 07cd634646
commit 020f212114
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
7 changed files with 13 additions and 12 deletions

View File

@ -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<App<Element>>
@ -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()

View File

@ -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 = `</${appSpaLoaderTag}>`
const appTemplate = APP_ROOT_OPEN_TAG + APP_ROOT_CLOSE_TAG

View File

@ -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')
},
}

View File

@ -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<string, unknown>).compatibilityVersion === 4)
return val ?? (((await get('future') as Record<string, unknown>).compatibilityVersion === 4) ? 'body' : 'within')
},
},
},

View File

@ -6,7 +6,7 @@ export default defineNuxtConfig({
'/ssr': { ssr: true },
},
experimental: {
spaPreloaderOutside: false,
spaLoadingTemplateLocation: 'within',
},
compatibilityDate: '2024-06-28',
})

View File

@ -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(`<div id="__nuxt"><div data-testid="loader">loading...</div>\n</div>`)

View File

@ -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({})