SSR: an error thrown inside <Suspense> rejects renderToReadableStream instead of falling back to client rendering #71
Version: @tanstack/redact 0.2.0 (compared with react-dom 19.2.0)
When a component throws during SSR inside a <Suspense> boundary, Redact's renderToReadableStream rejects the whole stream. React instead reports the error to onError, marks that boundary for client rendering (<!--$!-->), and still resolves the stream.
With TanStack Start, the whole page then returns 500, where React would have degraded only that boundary. We hit this when a third-party module threw at evaluation time inside a code-split route: React had been hiding the error, and Redact turned it into a 500.
Repro: https://github.com/ryoppippi/tanstack-redact-ssr-suspense-error-repro (pnpm install && node repro.mjs)
<html><body>
<Suspense fallback={<p>loading</p>}>
<Throws /> {/* throws during render */}
</Suspense>
</body></html>
react | sync throw | ok | onError=["render error inside Suspense"] | <!DOCTYPE html><html><head></head><body><!--$!--><template data-msg="Switched to client rendering because the server ren
react | lazy reject | ok | onError=["lazy chunk failed to evaluate"] | <!DOCTYPE html><html><head></head><body><!--$!--><template data-msg="Switched to client rendering because the server ren
redact | sync throw | REJECTS | onError=["render error inside Suspense"] | render error inside Suspense
redact | lazy reject | ok | onError=["lazy chunk failed to evaluate"] | <!DOCTYPE html><html><head></head><body><!--$?0--><div id="B:0"><p>loading</p></div><!--/$--></body></html>
The repro also has a related case: when a lazy() import rejects, Redact resolves the stream but leaves the boundary pending (<!--$?0--> plus the fallback). React marks it for client rendering instead.
Expected: match React. Call onError, emit the client-render marker for the failing boundary, and keep streaming the rest of the document.
tannerlinsley closed this
Sign in to join this conversation.
Thanks for the clear reproduction, including the lazy-import case. The boundary error-recovery fixes shipped in #76 with 0.2.1, and this looks fixed now. I'm closing it out, but please reopen this or share a fresh reproduction if either case still fails on 0.2.3.