Skip to content
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

perf(nuxt): ensure renderHTMLDocument return more compact result #24888

Merged
merged 9 commits into from Jan 4, 2024
14 changes: 7 additions & 7 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Expand Up @@ -412,9 +412,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
// Create render context
const htmlContext: NuxtRenderHTMLContext = {
island: Boolean(islandContext),
htmlAttrs: [htmlAttrs],
htmlAttrs: htmlAttrs ? [htmlAttrs] : [],
head: normalizeChunks([headTags, ssrContext.styles]),
bodyAttrs: [bodyAttrs],
bodyAttrs: bodyAttrs ? [bodyAttrs] : [],
bodyPrepend: normalizeChunks([bodyTagsOpen, ssrContext.teleports?.body]),
body: [process.env.NUXT_COMPONENT_ISLANDS ? replaceClientTeleport(ssrContext, replaceServerOnlyComponentsSlots(ssrContext, _rendered.html)) : _rendered.html],
bodyAppend: [bodyTags]
Expand Down Expand Up @@ -502,11 +502,11 @@ function joinAttrs (chunks: string[]) {
}

function renderHTMLDocument (html: NuxtRenderHTMLContext) {
return `<!DOCTYPE html>
<html ${joinAttrs(html.htmlAttrs)}>
<head>${joinTags(html.head)}</head>
<body ${joinAttrs(html.bodyAttrs)}>${joinTags(html.bodyPrepend)}${joinTags(html.body)}${joinTags(html.bodyAppend)}</body>
</html>`
return '<!DOCTYPE html>'
+ `<html${joinAttrs(html.htmlAttrs)}>`
+ `<head>${joinTags(html.head)}</head>`
+ `<body${joinAttrs(html.bodyAttrs)}>${joinTags(html.bodyPrepend)}${joinTags(html.body)}${joinTags(html.bodyAppend)}</body>`
+ '</html>'
}

async function renderInlineStyles (usedModules: Set<string> | string[]): Promise<Style[]> {
Expand Down