Unverified Commit bfee8eaa authored by Shu Ding's avatar Shu Ding Committed by GitHub

Move Edge SSR event `waitUntil` into the handler (#56404)

Fixes the code added in #56381 where the event isn't passed to the outer function, but the adapter inside.
parent 2c5a8b1a
......@@ -225,8 +225,6 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
}
const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)
globalThis.__next_private_global_wait_until__ = []
const render = getRender({
pagesType,
dev: ${dev},
......@@ -257,22 +255,12 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
export const ComponentMod = pageMod
export default async function nHandler (opts, event) {
const res = await adapter({
export default function nHandler (opts, event) {
return adapter({
...opts,
IncrementalCache,
handler: render
})
if (event && event.waitUntil) {
event.waitUntil(
Promise.all(
[res?.waitUntil, ...globalThis.__next_private_global_wait_until__]
)
)
}
return res
}`
return transformed
......
......@@ -5,6 +5,7 @@ import type { BuildManifest } from '../../../../server/get-page-files'
import type { ReactLoadableManifest } from '../../../../server/load-components'
import type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../../plugins/next-font-manifest-plugin'
import type { NextFetchEvent } from '../../../../server/web/spec-extension/fetch-event'
import WebServer from '../../../../server/web-server'
import {
......@@ -16,6 +17,15 @@ import { PrerenderManifest } from '../../..'
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
import { SizeLimit } from '../../../../../types'
const NEXT_PRIVATE_GLOBAL_WAIT_UNTIL = Symbol.for(
'__next_private_global_wait_until__'
)
// @ts-ignore
globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL] =
// @ts-ignore
globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL] || []
export function getRender({
dev,
page,
......@@ -143,13 +153,20 @@ export function getRender({
const handler = server.getRequestHandler()
return async function render(request: Request) {
return async function render(request: Request, event: NextFetchEvent) {
const extendedReq = new WebNextRequest(request)
const extendedRes = new WebNextResponse()
handler(extendedReq, extendedRes)
const result = await extendedRes.toResponse()
if (event && event.waitUntil) {
event.waitUntil(
// @ts-ignore
Promise.all([...globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL]])
)
}
// fetchMetrics is attached to the web request that going through the server,
// wait for the handler result is ready and attach it back to the original request.
;(request as any).fetchMetrics = extendedReq.fetchMetrics
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment