mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 14:45:15 +00:00
refactor(nuxt): use h3 early hints util (#8245)
This commit is contained in:
parent
573ed5ccda
commit
9388e65971
@ -1,7 +1,7 @@
|
|||||||
import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime'
|
import { createRenderer, renderResourceHeaders } from 'vue-bundle-renderer/runtime'
|
||||||
import type { RenderResponse } from 'nitropack'
|
import type { RenderResponse } from 'nitropack'
|
||||||
import type { Manifest } from 'vite'
|
import type { Manifest } from 'vite'
|
||||||
import { appendHeader, getQuery } from 'h3'
|
import { appendHeader, getQuery, writeEarlyHints } from 'h3'
|
||||||
import devalue from '@nuxt/devalue'
|
import devalue from '@nuxt/devalue'
|
||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { renderToString as _renderToString } from 'vue/server-renderer'
|
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()
|
const renderer = (process.env.NUXT_NO_SSR || ssrContext.noSSR) ? await getSPARenderer() : await getSSRRenderer()
|
||||||
|
|
||||||
// Render 103 Early Hints
|
// Render 103 Early Hints
|
||||||
if (!isRenderingPayload && !process.env.prerender && event.res.socket) {
|
if (!isRenderingPayload && !process.env.prerender) {
|
||||||
const { link } = renderResourceHeaders({}, renderer.rendererContext)
|
const { link } = renderResourceHeaders({}, renderer.rendererContext)
|
||||||
// TODO: use https://github.com/nodejs/node/pull/44180 when we drop support for node 16
|
writeEarlyHints(event, link)
|
||||||
event.res.socket!.write(`HTTP/1.1 103 Early Hints\r\nLink: ${link}\r\n\r\n`, 'utf-8')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const _rendered = await renderer.renderToString(ssrContext).catch((err) => {
|
const _rendered = await renderer.renderToString(ssrContext).catch((err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user