8000 feat(nuxt): make `app.rootId` optional by DamianGlowala Β· Pull Request #22528 Β· nuxt/nuxt Β· GitHub
[go: up one dir, main page]

Skip to content

feat(nuxt): make app.rootId optional #22528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: make app.rootId optional
  • Loading branch information
DamianGlowala committed Aug 7, 2023
commit 4be5a78d6aa990a5cf64123dbf0d39fee464b3f3
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { appRootId, appRootTag } from '#build/nuxt.config.mjs'

if (!globalThis.$fetch) {
globalThis.$fetch = $fetch.create({
Expand Down Expand Up @@ -75,7 +75,7 @@ if (process.client) {
try {
await nuxt.hooks.callHook('app:created', vueApp)
await nuxt.hooks.callHook('app:beforeMount', vueApp)
vueApp.mount('#' + appRootId)
vueApp.mount(appRootId ? `#${appRootId}` : `body > ${appRootTag}`)
await nuxt.hooks.callHook('app:mounted', vueApp)
await nextTick()
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const getSSRRenderer = lazyCachedFunction(async () => {
if (process.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
Expand All @@ -126,7 +126,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
Expand Down Expand Up @@ -185,7 +185,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'])

Expand Down
3 changes: 2 additions & 1 deletion packages/schema/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ export default defineUntypedSchema({

/**
* Customize Nuxt root element id.
*
* @type {string | false}
*/
rootId: '__nuxt',

/**
* Customize Nuxt root element tag.
*
*/
rootTag: 'div',
},
Expand Down
0