Skip to content

Conversation

gabrielmfern
Copy link
Member

@gabrielmfern gabrielmfern commented May 7, 2025

This is meant for partially fixing #1630 which is caused by a browser JS API trying to be used on the edge environment. React DOM does provide this react-dom/server.edge export that you can use which doesn't use that API, and works for raw edge environments, like Cloudflare Workers. I've tested this on our Cloudflare Workers Example

But, when running in Next.js on the edge, this error happens after this pull request:

(rsc)/./node_modules/@react-email/render/dist/edge-light/index.js
  Error [TypeError]: Cannot set properties of undefined (setting 'recentlyCreatedOwnerStacks')
    at new Promise (<anonymous>)
    at Generator.next (<anonymous>)

And according to vercel/next.js#71865, this happens because we're running React DOM in a React Server environment which isn't really allowed. Not sure what we can do to actually circumvent this, except for waiting for https://github.com/facebook/react/tree/main/packages/react-markup to get into a stable version, or use the experimental itself.

Copy link

changeset-bot bot commented May 7, 2025

🦋 Changeset detected

Latest commit: 8549fa1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@react-email/render Patch
@react-email/components Patch
playground Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented May 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
react-email Ready Ready Preview Comment Aug 19, 2025 5:43pm
react-email-demo Ready Ready Preview Comment Aug 19, 2025 5:43pm

Copy link

pkg-pr-new bot commented May 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/resend/react-email/@react-email/render@2225

commit: 8549fa1

@adrai
Copy link

adrai commented Jul 31, 2025

Does this address also this issue? #1630

@gabrielmfern
Copy link
Member Author

gabrielmfern commented Aug 19, 2025

@adrai yes, but introduces another error for Next.js running on the edge

@gabrielmfern gabrielmfern marked this pull request as ready for review August 19, 2025 17:06
@gabrielmfern gabrielmfern requested a review from a team as a code owner August 19, 2025 17:06
@gabrielmfern gabrielmfern requested review from rehanvdm and removed request for a team August 19, 2025 17:06
@gabrielmfern gabrielmfern changed the title feat(render): Use react-dom/server.edge on edge environments fix(render): edge environment errors with MessageChannel Aug 19, 2025
Copy link

@lucasfcosta lucasfcosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I also tested this manually on CloudFlare and was able to repro both the error and the fix.

As I discussed with @gabrielmfern it seems that 1.1.0 of @react-email/render doesn't cause this, so one has to ensure it's resolving to 1.2.0 to be able to reproduce it.

Once reproduced, this PR's changeset fixes it (pnpm i https://pkg.pr.new/resend/react-email/@react-email/render@2225).

@gabrielmfern gabrielmfern merged commit 036c46c into main Aug 20, 2025
14 checks passed
@gabrielmfern gabrielmfern deleted the feat/use-react-dom-edge-export branch August 20, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants