refactor(nuxt): use h3 early hints util (#8245)

This commit is contained in:
Daniel Roe 2022-10-17 10:16:19 +01:00 committed by GitHub
parent 573ed5ccda
commit 9388e65971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime'
import type { RenderResponse } from 'nitropack'
import type { Manifest } from 'vite'
import { appendHeader, getQuery } from 'h3'
import { appendHeader, getQuery, writeEarlyHints } from 'h3'
import devalue from '@nuxt/devalue'
import { joinURL } from 'ufo'
import { renderToString as _renderToString } from 'vue/server-renderer'
@ -157,10 +157,9 @@ export default defineRenderHandler(async (event) => {
const renderer = (process.env.NUXT_NO_SSR || ssrContext.noSSR) ? await getSPARenderer() : await getSSRRenderer()
// Render 103 Early Hints
if (!isRenderingPayload && !process.env.prerender && event.res.socket) {
if (!isRenderingPayload && !process.env.prerender) {
const { link } = renderResourceHeaders({}, renderer.rendererContext)
// TODO: use https://github.com/nodejs/node/pull/44180 when we drop support for node 16
event.res.socket!.write(`HTTP/1.1 103 Early Hints\r\nLink: ${link}\r\n\r\n`, 'utf-8')
writeEarlyHints(event, link)
}
const _rendered = await renderer.renderToString(ssrContext).catch((err) => {