mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
feat(nuxt): make app.rootId
optional (#22528)
This commit is contained in:
parent
e93195a317
commit
b5b2b47feb
@ -16,7 +16,7 @@ import plugins from '#build/plugins'
|
||||
// @ts-expect-error virtual file
|
||||
import RootComponent from '#build/root-component.mjs'
|
||||
// @ts-expect-error virtual file
|
||||
import { appRootId } from '#build/nuxt.config.mjs'
|
||||
import { vueAppRootContainer } from '#build/nuxt.config.mjs'
|
||||
|
||||
if (!globalThis.$fetch) {
|
||||
globalThis.$fetch = $fetch.create({
|
||||
@ -75,7 +75,7 @@ if (import.meta.client) {
|
||||
try {
|
||||
await nuxt.hooks.callHook('app:created', vueApp)
|
||||
await nuxt.hooks.callHook('app:beforeMount', vueApp)
|
||||
vueApp.mount('#' + appRootId)
|
||||
vueApp.mount(vueAppRootContainer)
|
||||
await nuxt.hooks.callHook('app:mounted', vueApp)
|
||||
await nextTick()
|
||||
} catch (err) {
|
||||
|
@ -117,7 +117,7 @@ const getSSRRenderer = lazyCachedFunction(async () => {
|
||||
if (import.meta.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
|
||||
renderer.rendererContext.updateManifest(await getClientManifest())
|
||||
}
|
||||
return `<${appRootTag} id="${appRootId}">${html}</${appRootTag}>`
|
||||
return `<${appRootTag}${appRootId ? ` id="${appRootId}"` : ''}>${html}</${appRootTag}>`
|
||||
}
|
||||
|
||||
return renderer
|
||||
@ -132,7 +132,7 @@ const getSPARenderer = lazyCachedFunction(async () => {
|
||||
|
||||
const options = {
|
||||
manifest,
|
||||
renderToString: () => `<${appRootTag} id="${appRootId}">${spaTemplate}</${appRootTag}>`,
|
||||
renderToString: () => `<${appRootTag}${appRootId ? ` id="${appRootId}"` : ''}>${spaTemplate}</${appRootTag}>`,
|
||||
buildAssetsURL
|
||||
}
|
||||
// Create SPA renderer and cache the result for all requests
|
||||
@ -191,7 +191,7 @@ async function getIslandContext (event: H3Event): Promise<NuxtIslandContext> {
|
||||
}
|
||||
|
||||
const PAYLOAD_URL_RE = process.env.NUXT_JSON_PAYLOADS ? /\/_payload(\.[a-zA-Z0-9]+)?.json(\?.*)?$/ : /\/_payload(\.[a-zA-Z0-9]+)?.js(\?.*)?$/
|
||||
const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag} id="${appRootId}">([\\s\\S]*)</${appRootTag}>$`)
|
||||
const ROOT_NODE_REGEX = new RegExp(`^<${appRootTag}${appRootId ? ` id="${appRootId}"` : ''}>([\\s\\S]*)</${appRootTag}>$`)
|
||||
|
||||
const PRERENDER_NO_SSR_ROUTES = new Set(['/index.html', '/200.html', '/404.html'])
|
||||
|
||||
|
@ -339,7 +339,8 @@ export const nuxtConfigTemplate = {
|
||||
`export const componentIslands = ${!!ctx.nuxt.options.experimental.componentIslands}`,
|
||||
`export const remoteComponentIslands = ${ctx.nuxt.options.experimental.componentIslands === 'local+remote'}`,
|
||||
`export const devPagesDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.dir.pages) : 'null'}`,
|
||||
`export const devRootDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.rootDir) : 'null'}`
|
||||
`export const devRootDir = ${ctx.nuxt.options.dev ? JSON.stringify(ctx.nuxt.options.rootDir) : 'null'}`,
|
||||
`export const vueAppRootContainer = ${ctx.nuxt.options.app.rootId ? `'#${ctx.nuxt.options.app.rootId}'` : `'body > ${ctx.nuxt.options.app.rootTag}'`}`
|
||||
].join('\n\n')
|
||||
}
|
||||
}
|
||||
|
@ -173,9 +173,11 @@ export default defineUntypedSchema({
|
||||
|
||||
/**
|
||||
* Customize Nuxt root element id.
|
||||
*
|
||||
* @type {string | false}
|
||||
*/
|
||||
rootId: {
|
||||
$resolve: val => val || '__nuxt'
|
||||
$resolve: val => val === false ? false : val || '__nuxt'
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user