Skip to content

Commit

Permalink
Await cacheReady during initial PPR prerender
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Jan 22, 2025
1 parent c9be398 commit 1c4783a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isPrerenderInterruptedError } from './dynamic-rendering'
*/
export function prerenderAndAbortInSequentialTasks<R>(
prerender: () => Promise<R>,
abort: () => void
abort: () => Promise<void>
): Promise<R> {
if (process.env.NEXT_RUNTIME === 'edge') {
throw new InvariantError(
Expand All @@ -26,7 +26,8 @@ export function prerenderAndAbortInSequentialTasks<R>(
})
setImmediate(() => {
abort()
resolve(pendingResult)
.then(() => resolve(pendingResult))
.catch(() => {})
})
})
}
Expand Down
9 changes: 5 additions & 4 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ async function prerenderToStream(
implicitTags: implicitTags,
renderSignal: initialClientController.signal,
controller: initialClientController,
cacheSignal: null,
cacheSignal,
dynamicTracking: null,
revalidate: INFINITE_CACHE,
expire: INFINITE_CACHE,
Expand Down Expand Up @@ -2761,7 +2761,8 @@ async function prerenderToStream(
: [bootstrapScript],
}
),
() => {
async () => {
await cacheSignal.cacheReady()
initialClientController.abort()
}
).catch((err) => {
Expand Down Expand Up @@ -2833,7 +2834,7 @@ async function prerenderToStream(
prerenderIsPending = false
return prerenderResult
},
() => {
async () => {
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()
Expand Down Expand Up @@ -2927,7 +2928,7 @@ async function prerenderToStream(
: [bootstrapScript],
}
),
() => {
async () => {
finalClientController.abort()
}
)
Expand Down

0 comments on commit 1c4783a

Please sign in to comment.