Skip to content

Commit 11f56c5

Browse files
authored
fix(react-email): ovewriting common user env variable (#2910)
1 parent a23801c commit 11f56c5

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

.changeset/fuzzy-shoes-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-email": patch
3+
---
4+
5+
fix RESEND_API_KEY being overwritten in email preview

.changeset/sweet-snails-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/preview-server": patch
3+
---
4+
5+
fix RESEND_API_KEY being overwritten in email preview

packages/preview-server/src/app/env.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/** ONLY ACCESSIBLE ON THE SERVER */
2-
export const userProjectLocation = process.env.USER_PROJECT_LOCATION!;
2+
export const userProjectLocation =
3+
process.env.REACT_EMAIL_INTERNAL_USER_PROJECT_LOCATION!;
34

45
/** ONLY ACCESSIBLE ON THE SERVER */
5-
export const previewServerLocation = process.env.PREVIEW_SERVER_LOCATION!;
6+
export const previewServerLocation =
7+
process.env.REACT_EMAIL_INTERNAL_PREVIEW_SERVER_LOCATION!;
68

79
/** ONLY ACCESSIBLE ON THE SERVER */
810
export const emailsDirectoryAbsolutePath =
9-
process.env.EMAILS_DIR_ABSOLUTE_PATH!;
11+
process.env.REACT_EMAIL_INTERNAL_EMAILS_DIR_ABSOLUTE_PATH!;
1012

1113
/** ONLY ACCESSIBLE ON THE SERVER */
12-
export const resendApiKey = process.env.RESEND_API_KEY;
14+
export const resendApiKey = process.env.REACT_EMAIL_INTERNAL_RESEND_API_KEY;
1315

1416
export const isBuilding = process.env.NEXT_PUBLIC_IS_BUILDING === 'true';
1517

packages/react-email/src/commands/build.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ const rootDir = ${isInMonorepo ? `'${rootDir.replace(/\\/g, '/')}'` : 'previewSe
3434
const nextConfig = {
3535
env: {
3636
NEXT_PUBLIC_IS_BUILDING: 'true',
37-
EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,
38-
EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),
39-
PREVIEW_SERVER_LOCATION: previewServerLocation,
40-
USER_PROJECT_LOCATION: userProjectLocation
37+
REACT_EMAIL_INTERNAL_EMAILS_DIR_RELATIVE_PATH: emailsDirRelativePath,
38+
REACT_EMAIL_INTERNAL_EMAILS_DIR_ABSOLUTE_PATH: path.resolve(userProjectLocation, emailsDirRelativePath),
39+
REACT_EMAIL_INTERNAL_PREVIEW_SERVER_LOCATION: previewServerLocation,
40+
REACT_EMAIL_INTERNAL_USER_PROJECT_LOCATION: userProjectLocation
4141
},
4242
turbopack: {
4343
root: rootDir,

packages/react-email/src/utils/preview/get-env-variables-for-preview-app.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ export const getEnvVariablesForPreviewApp = (
77
resendApiKey?: string,
88
) => {
99
return {
10-
EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
11-
EMAILS_DIR_ABSOLUTE_PATH: path.resolve(cwd, relativePathToEmailsDirectory),
12-
PREVIEW_SERVER_LOCATION: previewServerLocation,
13-
USER_PROJECT_LOCATION: cwd,
14-
RESEND_API_KEY: resendApiKey,
10+
REACT_EMAIL_INTERNAL_EMAILS_DIR_RELATIVE_PATH:
11+
relativePathToEmailsDirectory,
12+
REACT_EMAIL_INTERNAL_EMAILS_DIR_ABSOLUTE_PATH: path.resolve(
13+
cwd,
14+
relativePathToEmailsDirectory,
15+
),
16+
REACT_EMAIL_INTERNAL_PREVIEW_SERVER_LOCATION: previewServerLocation,
17+
REACT_EMAIL_INTERNAL_USER_PROJECT_LOCATION: cwd,
18+
REACT_EMAIL_INTERNAL_RESEND_API_KEY: resendApiKey,
1519
} as const;
1620
};

0 commit comments

Comments
 (0)