Skip to content

Render doesn't throw ReactDOMServer errors in browser, always returns HTML string. #2263

Open
@philinit

Description

@philinit

Describe the Bug

The render function always returns an HTML document, even if ReactDOMServer errors. While this prevents crashes, it obscures render failures, making error handling difficult. To address this, consider modifying render so errors can be programmatically detected and handled.

Which package is affected (leave empty if unsure)

@react-email/render

Link to the code that reproduces this issue

https://stackblitz.com/edit/vitejs-vite-btjincwb?file=src%2FApp.tsx

To Reproduce

If you pass a component that ReactDOMServer can’t render, the render returns:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--$!--><template data-msg="Switched to client rendering because the server rendering errored:...
Using the React Node directly instead of the Suspense wrapped node makes it possible to catch the error.

Expected Behavior

Consider making the Suspense wrapper optional via an options parameter. This allows wrapping the render call in a try-catch block to handle errors. A more intuitive approach is to have the render return an object like { code, error } instead of a string.

What's your node version? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions