feat(react-email): add email config support#3411
feat(react-email): add email config support#3411itsyoboieltr wants to merge 13 commits intoresend:canaryfrom
Conversation
🦋 Changeset detectedLatest commit: 7babd59 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
@itsyoboieltr is attempting to deploy a commit to the resend Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
2 issues found across 20 files
Confidence score: 3/5
- There is a concrete regression risk in
packages/react-email/src/cli/commands/build.ts: interpolatingemailConfigPathinto a single-quoted template without escaping can generate invalidnext.config.mjsand break builds for paths containing'. packages/react-email/src/config/get-email-config.tshas moderate validation looseness (arrays accepted as top-level config), which can let invalid exports pass silently and surface errors later.- Given a high-confidence medium-severity build-time issue plus another config-validation gap, this carries some user-facing risk and is worth fixing before merge if possible.
- Pay close attention to
packages/react-email/src/cli/commands/build.tsandpackages/react-email/src/config/get-email-config.ts- quoting/escaping in generated config and strict top-level config shape validation need verification.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/react-email/src/config/get-email-config.ts">
<violation number="1" location="packages/react-email/src/config/get-email-config.ts:22">
P2: Top-level config validation accepts arrays, so invalid config exports can pass silently.</violation>
</file>
<file name="packages/react-email/src/cli/commands/build.ts">
<violation number="1" location="packages/react-email/src/cli/commands/build.ts:39">
P2: Generated `next.config.mjs` can become invalid JavaScript because `emailConfigPath` is injected into a single-quoted string without escaping single quotes.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
commit: |
| @@ -0,0 +1,36 @@ | |||
| import fs from 'node:fs'; | |||
There was a problem hiding this comment.
I don't think this test is quite useful, as the code is quite simple and just reading it makes it clear if it's right or not. The only effect that this has is making it harder to change the code.
There was a problem hiding this comment.
removed the test as per your feedback
|
What kind of use case does this fix? Do we have any discussion about this already? I'd rather avoid we add a config file, and imo we should think of other options first. The ecosystem already has lots of config files, and they make projects messier and messier. |
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Requires human review: This PR introduces a significant new feature (external configuration support) that modifies core build, export, and preview logic. Such architectural changes require human review.
|
@gabrielmfern Hey, thanks for checking out my PR. There is some prior discussion here: #2334. I opened it almost a year ago, and some people expressed interest in the feature. My main use case is enabling user-provided custom esbuild plugins so email templates can use build-time macros and other compile-time transforms. In my case, that’s for lingui, but the same mechanism would also cover things like custom file loaders, macro transpilation, or loading env values during build. I understand the concern about adding another config file. I wouldn’t suggest it if there were a simpler workaround, but for build-time changes to email source there doesn’t seem to be a flexible alternative today (other than forking react-email to add plugin support). If there’s a better way to support this without a config file, I’m open to implementing it as well. |
Summary by cubic
Adds optional email config support to
react-email, letting projects defineemail.config.*to inject customesbuildplugins in exports and the preview UI. Shipsreact-email/configwith typed helpers and config validation. No breaking changes.New Features
email.config.ts|mts|cts|js|mjs|cjsviagetEmailConfigPath, and loads configs withgetEmailConfigusingjiti.react-email/configsubpath export withdefineConfig,getEmailConfig, andgetEmailConfigPath.REACT_EMAIL_INTERNAL_EMAIL_CONFIG_PATHto preview/build, and applies configesbuildplugins inexportTemplatesand UIgetEmailComponent.Bug Fixes
getEmailConfigPathreturnsundefinedwhen no config is found.esbuild.pluginsarray with helpful errors.jitiin preview/build and the UI to ensure runtime config loading.Written for commit 7babd59. Summary will update on new commits. Review in cubic