Skip to content

render does not work in the browser #1953

@hampustagerud

Description

@hampustagerud

Describe the Bug

Opening an issue since it was suggested to do that first instead of just opening a pull request 😄

I am trying to render an email in the browser but the react server is not imported properly (see reproduction) 🙂 I have solved this locally by patching the package and changing this line like this:

- const reactDOMServer = await import('react-dom/server');
+ const reactDOMServer = (await import('react-dom/server')).default;

This issue is that importing modules dynamically in the browser returns a Module and not the default export which typescript seem to suggest. Not sure if typescript can be reconfigured to reflect this, or if there's a better solution than this. The tests seem to pass and I can use the render function when trying out the fix locally at least!

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-8gysj2qp?file=src%2Fmain.tsx

To Reproduce

Use the render function in a browser.

Expected Behavior

The email is rendered to HTML.

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