Skip to content

Commit 7ea1c14

Browse files
shudingwbinnssmith
authored andcommitted
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.
1 parent 304e2c4 commit 7ea1c14

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
225225
}
226226
const nextFontManifest = maybeJSONParse(self.__NEXT_FONT_MANIFEST)
227227
228-
globalThis.__next_private_global_wait_until__ = []
229-
230228
const render = getRender({
231229
pagesType,
232230
dev: ${dev},
@@ -257,22 +255,12 @@ const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery> =
257255
258256
export const ComponentMod = pageMod
259257
260-
export default async function nHandler (opts, event) {
261-
const res = await adapter({
258+
export default function nHandler (opts, event) {
259+
return adapter({
262260
...opts,
263261
IncrementalCache,
264262
handler: render
265263
})
266-
267-
if (event && event.waitUntil) {
268-
event.waitUntil(
269-
Promise.all(
270-
[res?.waitUntil, ...globalThis.__next_private_global_wait_until__]
271-
)
272-
)
273-
}
274-
275-
return res
276264
}`
277265

278266
return transformed

packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { BuildManifest } from '../../../../server/get-page-files'
55
import type { ReactLoadableManifest } from '../../../../server/load-components'
66
import type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin'
77
import type { NextFontManifest } from '../../plugins/next-font-manifest-plugin'
8+
import type { NextFetchEvent } from '../../../../server/web/spec-extension/fetch-event'
89

910
import WebServer from '../../../../server/web-server'
1011
import {
@@ -16,6 +17,15 @@ import { PrerenderManifest } from '../../..'
1617
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
1718
import { SizeLimit } from '../../../../../types'
1819

20+
const NEXT_PRIVATE_GLOBAL_WAIT_UNTIL = Symbol.for(
21+
'__next_private_global_wait_until__'
22+
)
23+
24+
// @ts-ignore
25+
globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL] =
26+
// @ts-ignore
27+
globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL] || []
28+
1929
export function getRender({
2030
dev,
2131
page,
@@ -143,13 +153,20 @@ export function getRender({
143153

144154
const handler = server.getRequestHandler()
145155

146-
return async function render(request: Request) {
156+
return async function render(request: Request, event: NextFetchEvent) {
147157
const extendedReq = new WebNextRequest(request)
148158
const extendedRes = new WebNextResponse()
149159

150160
handler(extendedReq, extendedRes)
151161
const result = await extendedRes.toResponse()
152162

163+
if (event && event.waitUntil) {
164+
event.waitUntil(
165+
// @ts-ignore
166+
Promise.all([...globalThis[NEXT_PRIVATE_GLOBAL_WAIT_UNTIL]])
167+
)
168+
}
169+
153170
// fetchMetrics is attached to the web request that going through the server,
154171
// wait for the handler result is ready and attach it back to the original request.
155172
;(request as any).fetchMetrics = extendedReq.fetchMetrics

0 commit comments

Comments
 (0)