-
Notifications
You must be signed in to change notification settings - Fork 810
fix(react-email): Different react-dom version being used to render email templates #1431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gabrielmfern
merged 7 commits into
canary
from
fix/different-version-of-react-dom-rendering-templates-on-preview-server
May 10, 2024
Merged
fix(react-email): Different react-dom version being used to render email templates #1431
gabrielmfern
merged 7 commits into
canary
from
fix/different-version-of-react-dom-rendering-templates-on-preview-server
May 10, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
name: 'add-export-for-render-async', | ||
setup(b) { | ||
b.onLoad( | ||
{ filter: new RegExp(path.basename(emailPath)) }, |
Check failure
Code scanning / CodeQL
Regular expression injection
This regular expression is constructed from a [environment variable](1).
This regular expression is constructed from a [environment variable](2).
This regular expression is constructed from a [environment variable](3).
eea0258
to
e5d2948
Compare
2064b8b
to
05209a2
Compare
aa375e4
to
5f62de5
Compare
… email component
…orking and that its returning the renderAsync
This was mostly caused because `pnpm` doesn't allow for resolving `@react-email/render` when only `@react-email/components` is installed like npm or other package managers do. The solution for this was overriding the resolution of the module to get `renderAsync` from, and then trying both `@react-email/render` and `@react-email/components` until it actually errors.
…r @react-email/render or @react-email/components
a848b2a
to
ec948f7
Compare
vcapretz
approved these changes
May 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the issues that were causing #649. What was causing that issue
was that
@react-email/render
would importreact-dom
as the Nextbundled version, which would not be the same React instance used
inside the email templates, this caused that globals such as their
dispatcher would not have the expected values.
I noticed this was the cause of that issue after looking at our
updated trace on the error, and it pointed down into the
bundled version of
react-dom
insidenext
. The same issue wasalso happening for versions prior to
2.0
, so this was not a regression either.To fix this, I added a simple esbuild plugin to when the email template
is loaded, so that it adds a
export { renderAsync } from '@react-email/render'
at the end of it. This way, it would also give us access to the
renderAsync
and
react-dom
used in the user's project, so that this mismatch is not thereanymore.
Since I was experimenting a bit as well, I added in a test to make
sure the
getEmailComponent
function works properly at least with a localvery simple file.
How can I test this?
pnpm install
andturbo build
insidepackages/react-email
apps/demo/emails/test.tsx
npx tsx ../../packages/react-email/src/cli/index.ts dev
insideapps/demo
email dev
) does not work with any React hook #649 does not happen