mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-21 21:25:11 +00:00
perf(nuxt)!: don't call render:html
for server islands (#27889)
This commit is contained in:
parent
e8faa84d83
commit
5ac6aa574a
@ -461,23 +461,6 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
// remove certain tags for nuxt islands
|
||||
const { headTags, bodyTags, bodyTagsOpen, htmlAttrs, bodyAttrs } = await renderSSRHead(head, renderSSRHeadOptions)
|
||||
|
||||
// Create render context
|
||||
const htmlContext: NuxtRenderHTMLContext = {
|
||||
island: isRenderingIsland,
|
||||
htmlAttrs: htmlAttrs ? [htmlAttrs] : [],
|
||||
head: normalizeChunks([headTags]),
|
||||
bodyAttrs: bodyAttrs ? [bodyAttrs] : [],
|
||||
bodyPrepend: normalizeChunks([bodyTagsOpen, ssrContext.teleports?.body]),
|
||||
body: [
|
||||
componentIslands ? replaceIslandTeleports(ssrContext, _rendered.html) : _rendered.html,
|
||||
APP_TELEPORT_OPEN_TAG + (HAS_APP_TELEPORTS ? joinTags([ssrContext.teleports?.[`#${appTeleportAttrs.id}`]]) : '') + APP_TELEPORT_CLOSE_TAG,
|
||||
],
|
||||
bodyAppend: [bodyTags],
|
||||
}
|
||||
|
||||
// Allow hooking into the rendered result
|
||||
await nitroApp.hooks.callHook('render:html', htmlContext, { event })
|
||||
|
||||
// Response for component islands
|
||||
if (isRenderingIsland && islandContext) {
|
||||
const islandHead: NuxtIslandResponse['head'] = {
|
||||
@ -494,7 +477,7 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
const islandResponse: NuxtIslandResponse = {
|
||||
id: islandContext.id,
|
||||
head: islandHead,
|
||||
html: getServerComponentHTML(htmlContext.body),
|
||||
html: getServerComponentHTML(_rendered.html),
|
||||
components: getClientIslandResponse(ssrContext),
|
||||
slots: getSlotIslandResponse(ssrContext),
|
||||
}
|
||||
@ -517,6 +500,23 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
return response
|
||||
}
|
||||
|
||||
// Create render context
|
||||
const htmlContext: NuxtRenderHTMLContext = {
|
||||
island: isRenderingIsland,
|
||||
htmlAttrs: htmlAttrs ? [htmlAttrs] : [],
|
||||
head: normalizeChunks([headTags]),
|
||||
bodyAttrs: bodyAttrs ? [bodyAttrs] : [],
|
||||
bodyPrepend: normalizeChunks([bodyTagsOpen, ssrContext.teleports?.body]),
|
||||
body: [
|
||||
componentIslands ? replaceIslandTeleports(ssrContext, _rendered.html) : _rendered.html,
|
||||
APP_TELEPORT_OPEN_TAG + (HAS_APP_TELEPORTS ? joinTags([ssrContext.teleports?.[`#${appTeleportAttrs.id}`]]) : '') + APP_TELEPORT_CLOSE_TAG,
|
||||
],
|
||||
bodyAppend: [bodyTags],
|
||||
}
|
||||
|
||||
// Allow hooking into the rendered result
|
||||
await nitroApp.hooks.callHook('render:html', htmlContext, { event })
|
||||
|
||||
// Construct HTML response
|
||||
const response = {
|
||||
body: renderHTMLDocument(htmlContext),
|
||||
@ -637,8 +637,8 @@ function splitPayload (ssrContext: NuxtSSRContext) {
|
||||
/**
|
||||
* remove the root node from the html body
|
||||
*/
|
||||
function getServerComponentHTML (body: string[]): string {
|
||||
const match = body[0].match(ROOT_NODE_REGEX)
|
||||
function getServerComponentHTML (body: string): string {
|
||||
const match = body.match(ROOT_NODE_REGEX)
|
||||
return match ? match[1] : body[0]
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user