Skip to content

Commit

Permalink
guard against sync rerenders
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Dec 2, 2024
1 parent e1cb39d commit fab8705
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/renderStream/createRenderStream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,15 @@ export function createRenderStream<
}
const origRerender = ret.rerender
ret.rerender = async function rerender(rerenderUi: React.ReactNode) {
const previousRenderCount = stream.renders.length
try {
return await origRerender(rerenderUi)
} finally {
await stream.waitForNextRender()
// only wait for the next render if the rerender was not
// synchronous (React 17)
if (previousRenderCount === stream.renders.length) {
await stream.waitForNextRender()
}
}
}
return ret
Expand Down

0 comments on commit fab8705

Please sign in to comment.