Skip to content

Commit

Permalink
[dynamicIO] use new heuristic to track whether server render is dynamic
Browse files Browse the repository at this point in the history
Instead of relying on onError just use the timing of the prerender resolution to determine whether the server render completed before aborting.
  • Loading branch information
gnoff committed Dec 10, 2024
1 parent ef41607 commit 2f10a12
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2716,11 +2716,12 @@ async function prerenderToStream(
ctx,
res.statusCode === 404
)
let prerenderIsPending = true
const reactServerResult = (reactServerPrerenderResult =
await createReactServerPrerenderResult(
prerenderAndAbortInSequentialTasks(
() =>
workUnitAsyncStorage.run(
async () => {
const prerenderResult = await workUnitAsyncStorage.run(
// The store to scope
finalRenderPrerenderStore,
// The function to run
Expand All @@ -2730,17 +2731,33 @@ async function prerenderToStream(
clientReferenceManifest.clientModules,
{
onError: (err: unknown) => {
// TODO we can remove this once https://github.com/facebook/react/pull/31715 lands
// because we won't have onError calls when halting the prerender
if (finalServerController.signal.aborted) {
serverIsDynamic = true
return
}

return serverComponentsErrorHandler(err)
},
signal: finalServerController.signal,
}
),
)
prerenderIsPending = false
return prerenderResult
},
() => {
if (finalServerController.signal.aborted) {
// If the server controller is already aborted we must have called something
// that required aborting the prerender synchronously such as with new Date()
serverIsDynamic = true
return
}

if (prerenderIsPending) {
// If prerenderIsPending then we have blocked for longer than a Task and we assume
// there is something unfinished.
serverIsDynamic = true
}
finalServerController.abort()
}
)
Expand Down

0 comments on commit 2f10a12

Please # to comment.