resend / react-email

💌 Build and send emails using React
https://react.email
MIT License
12.57k stars 571 forks source link

fix(react-email): Missing URLSearchParams on global context for email VM #1419

Closed vlaforet closed 4 weeks ago

vlaforet commented 4 weeks ago

Background

As we need to pre-import the modules from Node into the app before loading them with vm we also need to define the context in which the code will run for us to get the email's component, this means that we need to pass in a few other global things like Buffer that the global dynamically doesn't contain.

What was the issue?

That being said, something that was missing from the global context was the URLSearchParams class, which this PR adds. Similar to #1232.

How can I test to make sure it's fixed?

  1. Run npx tsx ../../packages/react-email/src/cli/index.ts dev inside of ./apps/demo
  2. Modify the email at ./apps/demo/emails/airbnb-review.tsx by adding the following:
    console.log(new URLSearchParams(""));
  3. Open http://localhost:3000/preview/airbnb-review.tsx
  4. Verify that this errors with "Invalid path" instead of with URLSearchParams is not defined
vercel[bot] commented 4 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-email-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2024 5:43pm
vercel[bot] commented 4 weeks ago

@vlaforet is attempting to deploy a commit to the resend Team on Vercel.

A member of the Team first needs to authorize it.