Skip to content

Commit

Permalink
drain the microtask queue before returning from peekRender
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 29, 2024
1 parent 932f938 commit 451d67a
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/renderStream/createRenderStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,27 @@ export function createRenderStream<
return stream.renders.length
},
async peekRender(options: NextRenderOptions = {}) {
if (iteratorPosition < stream.renders.length) {
const peekedRender = stream.renders[iteratorPosition]
try {
if (iteratorPosition < stream.renders.length) {
const peekedRender = stream.renders[iteratorPosition]

if (peekedRender.phase === 'snapshotError') {
throw peekedRender.error
}
if (peekedRender.phase === 'snapshotError') {
throw peekedRender.error
}

return peekedRender
return peekedRender
}
return await stream
.waitForNextRender(options)
.catch(rethrowWithCapturedStackTrace(stream.peekRender))
} finally {
/** drain microtask queue */
await new Promise<void>(resolve => {
setTimeout(() => {
resolve()
}, 0)
})
}
return stream
.waitForNextRender(options)
.catch(rethrowWithCapturedStackTrace(stream.peekRender))
},
takeRender: markAssertable(async function takeRender(
options: NextRenderOptions = {},
Expand Down

0 comments on commit 451d67a

Please sign in to comment.