react-email 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cli/index.js +90 -94
  3. package/dist/cli/index.mjs +69 -58
  4. package/dist/index.d.mts +20 -0
  5. package/dist/index.d.ts +20 -0
  6. package/dist/index.js +96 -0
  7. package/dist/index.mjs +21 -0
  8. package/dist/package/index.d.mts +33 -0
  9. package/dist/package/index.d.ts +33 -0
  10. package/dist/package/index.js +62 -0
  11. package/dist/package/index.mjs +7 -0
  12. package/dist/preview/.next/BUILD_ID +1 -1
  13. package/dist/preview/.next/app-build-manifest.json +31 -31
  14. package/dist/preview/.next/app-path-routes-manifest.json +1 -1
  15. package/dist/preview/.next/build-manifest.json +14 -14
  16. package/dist/preview/.next/cache/.rscinfo +1 -1
  17. package/dist/preview/.next/cache/eslint/.cache_1vyas3k +1 -0
  18. package/dist/preview/.next/cache/webpack/client-production/0.pack +0 -0
  19. package/dist/preview/.next/cache/webpack/client-production/index.pack +0 -0
  20. package/dist/preview/.next/cache/webpack/edge-server-production/index.pack +0 -0
  21. package/dist/preview/.next/cache/webpack/server-production/0.pack +0 -0
  22. package/dist/preview/.next/cache/webpack/server-production/index.pack +0 -0
  23. package/dist/preview/.next/diagnostics/framework.json +1 -1
  24. package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
  25. package/dist/preview/.next/next-server.js.nft.json +1 -1
  26. package/dist/preview/.next/prerender-manifest.json +1 -1
  27. package/dist/preview/.next/required-server-files.json +1 -1
  28. package/dist/preview/.next/server/app/_not-found/page.js +1 -1
  29. package/dist/preview/.next/server/app/_not-found/page.js.nft.json +1 -1
  30. package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  31. package/dist/preview/.next/server/app/favicon.ico/route.js +1 -1
  32. package/dist/preview/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  33. package/dist/preview/.next/server/app/page.js +1 -1
  34. package/dist/preview/.next/server/app/page.js.nft.json +1 -1
  35. package/dist/preview/.next/server/app/page_client-reference-manifest.js +1 -1
  36. package/dist/preview/.next/server/app/preview/[...slug]/page.js +6 -6
  37. package/dist/preview/.next/server/app/preview/[...slug]/page.js.nft.json +1 -1
  38. package/dist/preview/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -1
  39. package/dist/preview/.next/server/app-paths-manifest.json +1 -1
  40. package/dist/preview/.next/server/chunks/300.js +13 -0
  41. package/dist/preview/.next/server/chunks/420.js +1 -0
  42. package/dist/preview/.next/server/chunks/625.js +5 -0
  43. package/dist/preview/.next/server/chunks/631.js +6 -0
  44. package/dist/preview/.next/server/chunks/720.js +10 -0
  45. package/dist/preview/.next/server/middleware-build-manifest.js +1 -1
  46. package/dist/preview/.next/server/next-font-manifest.js +1 -1
  47. package/dist/preview/.next/server/next-font-manifest.json +1 -1
  48. package/dist/preview/.next/server/pages/500.html +1 -1
  49. package/dist/preview/.next/server/pages/_app.js +1 -1
  50. package/dist/preview/.next/server/pages/_app.js.nft.json +1 -1
  51. package/dist/preview/.next/server/pages/_document.js +1 -1
  52. package/dist/preview/.next/server/pages/_document.js.nft.json +1 -1
  53. package/dist/preview/.next/server/pages/_error.js +1 -1
  54. package/dist/preview/.next/server/pages/_error.js.nft.json +1 -1
  55. package/dist/preview/.next/server/server-reference-manifest.js +1 -1
  56. package/dist/preview/.next/server/server-reference-manifest.json +1 -1
  57. package/dist/preview/.next/static/6K68y2QEZ1dLbv-Xhi30p/_buildManifest.js +1 -0
  58. package/dist/preview/.next/static/chunks/12-b9450aa0845e7574.js +1 -0
  59. package/dist/preview/.next/static/chunks/154-69b91a0c2fd801b8.js +1 -0
  60. package/dist/preview/.next/static/chunks/447-886131c35ca42b91.js +1 -0
  61. package/dist/preview/.next/static/chunks/5fec7a0a-5179023f3f5a9421.js +1 -0
  62. package/dist/preview/.next/static/chunks/797-46f6c20952f0a280.js +2 -0
  63. package/dist/preview/.next/static/chunks/{677-dd9544a8249ca33a.js → 860-38d96c8819ba6f19.js} +1 -1
  64. package/dist/preview/.next/static/chunks/app/_not-found/page-96d3eac723be3ee2.js +1 -0
  65. package/dist/preview/.next/static/chunks/app/layout-e1b6f1534cbbe5bd.js +1 -0
  66. package/dist/preview/.next/static/chunks/app/page-2c3e297e38c526ef.js +1 -0
  67. package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-2b4988ba6daf34e1.js +1 -0
  68. package/dist/preview/.next/static/chunks/framework-e7cae9cecd5c9ba2.js +1 -0
  69. package/dist/preview/.next/static/chunks/main-app-2c7f96205a73f128.js +1 -0
  70. package/dist/preview/.next/static/chunks/main-df761fde212f9cda.js +1 -0
  71. package/dist/preview/.next/static/chunks/pages/_app-203a61b355820ccf.js +1 -0
  72. package/dist/preview/.next/static/chunks/pages/_error-1764ca54938748c8.js +1 -0
  73. package/dist/preview/.next/static/chunks/{webpack-08c76d9f8dd5b0f0.js → webpack-9255716c9496e606.js} +1 -1
  74. package/dist/preview/.next/static/css/{eecb5c96aca6bd9e.css → ec5d7e66bd3b6cb8.css} +1 -1
  75. package/dist/preview/.next/trace +20 -2
  76. package/dist/preview/.next/types/app/layout.ts +1 -1
  77. package/dist/preview/.next/types/app/preview/[...slug]/page.ts +1 -1
  78. package/dist/preview/.next/types/cache-life.d.ts +2 -0
  79. package/next-env.d.ts +1 -1
  80. package/package.json +6 -6
  81. package/src/actions/get-email-path-from-slug.ts +3 -2
  82. package/src/actions/get-emails-directory-metadata.spec.ts +1 -0
  83. package/src/actions/get-emails-directory-metadata.ts +62 -59
  84. package/src/actions/render-email-by-path.tsx +16 -5
  85. package/src/app/preview/[...slug]/page.tsx +19 -9
  86. package/src/app/preview/[...slug]/preview.tsx +6 -7
  87. package/src/contexts/emails.tsx +2 -56
  88. package/src/hooks/use-email-rendering-result.ts +44 -0
  89. package/src/hooks/use-rendering-metadata.ts +5 -5
  90. package/src/package/body/dist/index.d.mts +6 -0
  91. package/src/package/body/dist/index.d.ts +6 -0
  92. package/src/package/body/dist/index.js +79 -0
  93. package/src/package/body/dist/index.mjs +45 -0
  94. package/src/package/button/dist/index.d.mts +6 -0
  95. package/src/package/button/dist/index.d.ts +6 -0
  96. package/src/package/button/dist/index.js +252 -0
  97. package/src/package/button/dist/index.mjs +218 -0
  98. package/src/package/code-block/dist/index.d.mts +4906 -0
  99. package/src/package/code-block/dist/index.d.ts +4906 -0
  100. package/src/package/code-block/dist/index.js +18205 -0
  101. package/src/package/code-block/dist/index.mjs +18133 -0
  102. package/src/package/code-inline/dist/index.d.mts +11 -0
  103. package/src/package/code-inline/dist/index.d.ts +11 -0
  104. package/src/package/code-inline/dist/index.js +106 -0
  105. package/src/package/code-inline/dist/index.mjs +72 -0
  106. package/src/package/column/dist/index.d.mts +6 -0
  107. package/src/package/column/dist/index.d.ts +6 -0
  108. package/src/package/column/dist/index.js +79 -0
  109. package/src/package/column/dist/index.mjs +45 -0
  110. package/src/package/components/dist/index.d.mts +20 -0
  111. package/src/package/components/dist/index.d.ts +20 -0
  112. package/src/package/components/dist/index.js +62 -0
  113. package/src/package/components/dist/index.mjs +21 -0
  114. package/src/package/container/dist/index.d.mts +6 -0
  115. package/src/package/container/dist/index.d.ts +6 -0
  116. package/src/package/container/dist/index.js +93 -0
  117. package/src/package/container/dist/index.mjs +59 -0
  118. package/src/package/font/dist/index.d.mts +25 -0
  119. package/src/package/font/dist/index.d.ts +25 -0
  120. package/src/package/font/dist/index.js +55 -0
  121. package/src/package/font/dist/index.mjs +28 -0
  122. package/src/package/head/dist/index.d.mts +6 -0
  123. package/src/package/head/dist/index.d.ts +6 -0
  124. package/src/package/head/dist/index.js +83 -0
  125. package/src/package/head/dist/index.mjs +49 -0
  126. package/src/package/heading/dist/index.d.mts +43 -0
  127. package/src/package/heading/dist/index.d.ts +43 -0
  128. package/src/package/heading/dist/index.js +113 -0
  129. package/src/package/heading/dist/index.mjs +79 -0
  130. package/src/package/hr/dist/index.d.mts +6 -0
  131. package/src/package/hr/dist/index.d.ts +6 -0
  132. package/src/package/hr/dist/index.js +89 -0
  133. package/src/package/hr/dist/index.mjs +55 -0
  134. package/src/package/html/dist/index.d.mts +6 -0
  135. package/src/package/html/dist/index.d.ts +6 -0
  136. package/src/package/html/dist/index.js +79 -0
  137. package/src/package/html/dist/index.mjs +45 -0
  138. package/src/package/img/dist/index.d.mts +6 -0
  139. package/src/package/img/dist/index.d.ts +6 -0
  140. package/src/package/img/dist/index.js +94 -0
  141. package/src/package/img/dist/index.mjs +60 -0
  142. package/src/package/link/dist/index.d.mts +6 -0
  143. package/src/package/link/dist/index.d.ts +6 -0
  144. package/src/package/link/dist/index.js +90 -0
  145. package/src/package/link/dist/index.mjs +56 -0
  146. package/src/package/markdown/dist/index.d.mts +15 -0
  147. package/src/package/markdown/dist/index.d.ts +15 -0
  148. package/src/package/markdown/dist/index.js +92 -0
  149. package/src/package/markdown/dist/index.mjs +58 -0
  150. package/src/package/preview/dist/index.d.mts +12 -0
  151. package/src/package/preview/dist/index.d.ts +12 -0
  152. package/src/package/preview/dist/index.js +108 -0
  153. package/src/package/preview/dist/index.mjs +73 -0
  154. package/src/package/render/dist/browser/index.d.mts +24 -0
  155. package/src/package/render/dist/browser/index.d.ts +24 -0
  156. package/src/package/render/dist/browser/index.js +250 -0
  157. package/src/package/render/dist/browser/index.mjs +214 -0
  158. package/src/package/render/dist/index.d.mts +23 -0
  159. package/src/package/render/dist/index.d.ts +23 -0
  160. package/src/package/render/dist/index.js +768 -0
  161. package/src/package/render/dist/index.mjs +733 -0
  162. package/src/package/render/dist/node/index.d.mts +27 -0
  163. package/src/package/render/dist/node/index.d.ts +27 -0
  164. package/src/package/render/dist/node/index.js +212 -0
  165. package/src/package/render/dist/node/index.mjs +176 -0
  166. package/src/package/row/dist/index.d.mts +10 -0
  167. package/src/package/row/dist/index.d.ts +10 -0
  168. package/src/package/row/dist/index.js +93 -0
  169. package/src/package/row/dist/index.mjs +59 -0
  170. package/src/package/section/dist/index.d.mts +6 -0
  171. package/src/package/section/dist/index.d.ts +6 -0
  172. package/src/package/section/dist/index.js +93 -0
  173. package/src/package/section/dist/index.mjs +59 -0
  174. package/src/package/tailwind/dist/index.d.ts +19 -0
  175. package/src/package/tailwind/dist/index.js +48 -0
  176. package/src/package/tailwind/dist/index.mjs +17167 -0
  177. package/src/package/tailwind/dist/tailwindcss/config.d.ts +376 -0
  178. package/src/package/tailwind/dist/tailwindcss/generated/.gitkeep +0 -0
  179. package/src/package/tailwind/dist/tailwindcss/generated/colors.d.ts +298 -0
  180. package/src/package/tailwind/dist/tailwindcss/generated/corePluginList.d.ts +1 -0
  181. package/src/package/tailwind/dist/tailwindcss/generated/default-theme.d.ts +397 -0
  182. package/src/package/tailwind/dist/tailwindcss/index.d.ts +11 -0
  183. package/src/package/text/dist/index.d.mts +6 -0
  184. package/src/package/text/dist/index.d.ts +6 -0
  185. package/src/package/text/dist/index.js +89 -0
  186. package/src/package/text/dist/index.mjs +55 -0
  187. package/src/utils/types/hot-reload-event.ts +3 -6
  188. package/dist/preview/.next/cache/eslint/.cache_117y9un +0 -1
  189. package/dist/preview/.next/cache/webpack/client-production/1.pack +0 -0
  190. package/dist/preview/.next/cache/webpack/client-production/2.pack +0 -0
  191. package/dist/preview/.next/cache/webpack/client-production/index.pack.old +0 -0
  192. package/dist/preview/.next/cache/webpack/server-production/1.pack +0 -0
  193. package/dist/preview/.next/cache/webpack/server-production/index.pack.old +0 -0
  194. package/dist/preview/.next/server/chunks/185.js +0 -1
  195. package/dist/preview/.next/server/chunks/270.js +0 -10
  196. package/dist/preview/.next/server/chunks/323.js +0 -4
  197. package/dist/preview/.next/server/chunks/867.js +0 -7
  198. package/dist/preview/.next/server/chunks/887.js +0 -5
  199. package/dist/preview/.next/server/chunks/931.js +0 -6
  200. package/dist/preview/.next/server/chunks/945.js +0 -13
  201. package/dist/preview/.next/static/chunks/131-f4d810c5beddfab6.js +0 -2
  202. package/dist/preview/.next/static/chunks/174-3e37f7e70124a32b.js +0 -1
  203. package/dist/preview/.next/static/chunks/406-3d68715e81289266.js +0 -1
  204. package/dist/preview/.next/static/chunks/41423bf1-6f7e6cd2fc1291c3.js +0 -1
  205. package/dist/preview/.next/static/chunks/968-7fddcc3bfb4ada61.js +0 -1
  206. package/dist/preview/.next/static/chunks/app/_not-found/page-53e238cd8965175e.js +0 -1
  207. package/dist/preview/.next/static/chunks/app/layout-94f263ae274f6f80.js +0 -1
  208. package/dist/preview/.next/static/chunks/app/page-68f0897ebaef4c9c.js +0 -1
  209. package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-823cfe936f21397d.js +0 -1
  210. package/dist/preview/.next/static/chunks/framework-9780ea70a2600e73.js +0 -1
  211. package/dist/preview/.next/static/chunks/main-app-d2690e9b3dbe4561.js +0 -1
  212. package/dist/preview/.next/static/chunks/main-f2abbba525af0515.js +0 -1
  213. package/dist/preview/.next/static/chunks/pages/_app-ac8e4ba1a8597f2e.js +0 -1
  214. package/dist/preview/.next/static/chunks/pages/_error-88e591eedab147f8.js +0 -1
  215. package/dist/preview/.next/static/yKpx8LQApEcHL50eu16RD/_buildManifest.js +0 -1
  216. /package/dist/preview/.next/static/{yKpx8LQApEcHL50eu16RD → 6K68y2QEZ1dLbv-Xhi30p}/_ssgManifest.js +0 -0
@@ -1,4 +1,4 @@
1
- // File: /home/gabriel/Projects/Resend/react-email.git/primary/packages/react-email/src/app/layout.tsx
1
+ // File: /home/gabriel/Projects/resend/react-email/packages/react-email/src/app/layout.tsx
2
2
  import * as entry from '../../../src/app/layout.js'
3
3
  import type { ResolvingMetadata, ResolvingViewport } from 'next/dist/lib/metadata/types/metadata-interface.js'
4
4
 
@@ -1,4 +1,4 @@
1
- // File: /home/gabriel/Projects/Resend/react-email.git/primary/packages/react-email/src/app/preview/[...slug]/page.tsx
1
+ // File: /home/gabriel/Projects/resend/react-email/packages/react-email/src/app/preview/[...slug]/page.tsx
2
2
  import * as entry from '../../../../../src/app/preview/[...slug]/page.js'
3
3
  import type { ResolvingMetadata, ResolvingViewport } from 'next/dist/lib/metadata/types/metadata-interface.js'
4
4
 
@@ -5,6 +5,8 @@ declare module 'next/cache' {
5
5
  export {
6
6
  revalidateTag,
7
7
  revalidatePath,
8
+ unstable_expireTag,
9
+ unstable_expirePath,
8
10
  } from 'next/dist/server/web/spec-extension/revalidate'
9
11
  export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store'
10
12
 
package/next-env.d.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  /// <reference types="next/image-types/global" />
3
3
 
4
4
  // NOTE: This file should not be edited
5
- // see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
5
+ // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-email",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "A live preview of your emails right in your browser.",
5
5
  "bin": {
6
6
  "email": "./dist/cli/index.js"
@@ -22,14 +22,14 @@
22
22
  "@babel/core": "7.24.5",
23
23
  "@babel/parser": "7.24.5",
24
24
  "chalk": "4.1.2",
25
- "chokidar": "^4.0.1",
25
+ "chokidar": "4.0.3",
26
26
  "commander": "11.1.0",
27
27
  "debounce": "2.0.0",
28
28
  "esbuild": "0.19.11",
29
29
  "glob": "10.3.4",
30
30
  "log-symbols": "4.1.0",
31
31
  "mime-types": "2.1.35",
32
- "next": "15.0.4",
32
+ "next": "15.1.2",
33
33
  "normalize-path": "3.0.0",
34
34
  "ora": "5.4.1",
35
35
  "socket.io": "4.8.0"
@@ -45,13 +45,13 @@
45
45
  "@types/babel__core": "7.20.5",
46
46
  "@types/fs-extra": "11.0.1",
47
47
  "@types/mime-types": "2.1.4",
48
- "@types/node": "18.0.0",
48
+ "@types/node": "22.10.2",
49
49
  "@types/normalize-path": "3.0.2",
50
50
  "@types/react": "^19",
51
51
  "@types/react-dom": "^19",
52
52
  "@types/webpack": "5.28.5",
53
53
  "@vercel/style-guide": "5.1.0",
54
- "autoprefixer": "10.4.14",
54
+ "autoprefixer": "10.4.20",
55
55
  "clsx": "2.1.0",
56
56
  "eslint": "8.50.0",
57
57
  "eslint-config-prettier": "9.0.0",
@@ -72,7 +72,7 @@
72
72
  "tsx": "4.9.0",
73
73
  "typescript": "5.1.6",
74
74
  "vitest": "1.1.3",
75
- "@react-email/render": "1.0.3"
75
+ "@react-email/render": "1.0.4"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "tsup-node && node build-preview-server.mjs",
@@ -1,10 +1,11 @@
1
1
  'use server';
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
+ import { cache } from 'react';
4
5
  import { emailsDirectoryAbsolutePath } from '../utils/emails-directory-absolute-path';
5
6
 
6
7
  // eslint-disable-next-line @typescript-eslint/require-await
7
- export const getEmailPathFromSlug = async (slug: string) => {
8
+ export const getEmailPathFromSlug = cache(async (slug: string) => {
8
9
  if (['.tsx', '.jsx', '.ts', '.js'].includes(path.extname(slug)))
9
10
  return path.join(emailsDirectoryAbsolutePath, slug);
10
11
 
@@ -25,4 +26,4 @@ export const getEmailPathFromSlug = async (slug: string) => {
25
26
 
26
27
  This is most likely not an issue with the preview server. It most likely is that the email doesn't exist.`,
27
28
  );
28
- };
29
+ });
@@ -44,6 +44,7 @@ test('getEmailsDirectoryMetadata on demo emails', async () => {
44
44
  relativePath: 'notifications',
45
45
  emailFilenames: [
46
46
  'github-access-token',
47
+ 'papermark-year-in-review',
47
48
  'vercel-invite-user',
48
49
  'yelp-recent-login',
49
50
  ],
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
+ import { cache } from 'react';
5
6
 
6
7
  const isFileAnEmail = (fullPath: string): boolean => {
7
8
  const stat = fs.statSync(fullPath);
@@ -57,64 +58,66 @@ const mergeDirectoriesWithSubDirectories = (
57
58
  return currentResultingMergedDirectory;
58
59
  };
59
60
 
60
- export const getEmailsDirectoryMetadata = async (
61
- absolutePathToEmailsDirectory: string,
62
- keepFileExtensions = false,
63
- isSubDirectory = false,
64
-
65
- baseDirectoryPath = absolutePathToEmailsDirectory,
66
- ): Promise<EmailsDirectory | undefined> => {
67
- if (!fs.existsSync(absolutePathToEmailsDirectory)) return;
68
-
69
- const dirents = await fs.promises.readdir(absolutePathToEmailsDirectory, {
70
- withFileTypes: true,
71
- });
72
-
73
- const emailFilenames = dirents
74
- .filter((dirent) =>
75
- isFileAnEmail(path.join(absolutePathToEmailsDirectory, dirent.name)),
76
- )
77
- .map((dirent) =>
78
- keepFileExtensions
79
- ? dirent.name
80
- : dirent.name.replace(path.extname(dirent.name), ''),
81
- );
61
+ export const getEmailsDirectoryMetadata = cache(
62
+ async (
63
+ absolutePathToEmailsDirectory: string,
64
+ keepFileExtensions = false,
65
+ isSubDirectory = false,
66
+
67
+ baseDirectoryPath = absolutePathToEmailsDirectory,
68
+ ): Promise<EmailsDirectory | undefined> => {
69
+ if (!fs.existsSync(absolutePathToEmailsDirectory)) return;
82
70
 
83
- const subDirectories = await Promise.all(
84
- dirents
85
- .filter(
86
- (dirent) =>
87
- dirent.isDirectory() &&
88
- !dirent.name.startsWith('_') &&
89
- dirent.name !== 'static',
71
+ const dirents = await fs.promises.readdir(absolutePathToEmailsDirectory, {
72
+ withFileTypes: true,
73
+ });
74
+
75
+ const emailFilenames = dirents
76
+ .filter((dirent) =>
77
+ isFileAnEmail(path.join(absolutePathToEmailsDirectory, dirent.name)),
90
78
  )
91
- .map((dirent) => {
92
- const direntAbsolutePath = path.join(
93
- absolutePathToEmailsDirectory,
94
- dirent.name,
95
- );
96
-
97
- return getEmailsDirectoryMetadata(
98
- direntAbsolutePath,
99
- keepFileExtensions,
100
- true,
101
- baseDirectoryPath,
102
- ) as Promise<EmailsDirectory>;
103
- }),
104
- );
105
-
106
- const emailsMetadata = {
107
- absolutePath: absolutePathToEmailsDirectory,
108
- relativePath: path.relative(
109
- baseDirectoryPath,
110
- absolutePathToEmailsDirectory,
111
- ),
112
- directoryName: absolutePathToEmailsDirectory.split(path.sep).pop()!,
113
- emailFilenames,
114
- subDirectories,
115
- } satisfies EmailsDirectory;
116
-
117
- return isSubDirectory
118
- ? mergeDirectoriesWithSubDirectories(emailsMetadata)
119
- : emailsMetadata;
120
- };
79
+ .map((dirent) =>
80
+ keepFileExtensions
81
+ ? dirent.name
82
+ : dirent.name.replace(path.extname(dirent.name), ''),
83
+ );
84
+
85
+ const subDirectories = await Promise.all(
86
+ dirents
87
+ .filter(
88
+ (dirent) =>
89
+ dirent.isDirectory() &&
90
+ !dirent.name.startsWith('_') &&
91
+ dirent.name !== 'static',
92
+ )
93
+ .map((dirent) => {
94
+ const direntAbsolutePath = path.join(
95
+ absolutePathToEmailsDirectory,
96
+ dirent.name,
97
+ );
98
+
99
+ return getEmailsDirectoryMetadata(
100
+ direntAbsolutePath,
101
+ keepFileExtensions,
102
+ true,
103
+ baseDirectoryPath,
104
+ ) as Promise<EmailsDirectory>;
105
+ }),
106
+ );
107
+
108
+ const emailsMetadata = {
109
+ absolutePath: absolutePathToEmailsDirectory,
110
+ relativePath: path.relative(
111
+ baseDirectoryPath,
112
+ absolutePathToEmailsDirectory,
113
+ ),
114
+ directoryName: absolutePathToEmailsDirectory.split(path.sep).pop()!,
115
+ emailFilenames,
116
+ subDirectories,
117
+ } satisfies EmailsDirectory;
118
+
119
+ return isSubDirectory
120
+ ? mergeDirectoriesWithSubDirectories(emailsMetadata)
121
+ : emailsMetadata;
122
+ },
123
+ );
@@ -21,9 +21,16 @@ export type EmailRenderingResult =
21
21
  error: ErrorObject;
22
22
  };
23
23
 
24
+ const cache = new Map<string, EmailRenderingResult>();
25
+
24
26
  export const renderEmailByPath = async (
25
27
  emailPath: string,
28
+ invalidatingCache = false,
26
29
  ): Promise<EmailRenderingResult> => {
30
+ if (invalidatingCache) cache.delete(emailPath);
31
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
32
+ if (cache.has(emailPath)) return cache.get(emailPath)!;
33
+
27
34
  const timeBeforeEmailRendered = performance.now();
28
35
 
29
36
  const emailFilename = path.basename(emailPath);
@@ -36,14 +43,14 @@ export const renderEmailByPath = async (
36
43
  registerSpinnerAutostopping(spinner);
37
44
  }
38
45
 
39
- const result = await getEmailComponent(emailPath);
46
+ const componentResult = await getEmailComponent(emailPath);
40
47
 
41
- if ('error' in result) {
48
+ if ('error' in componentResult) {
42
49
  spinner?.stopAndPersist({
43
50
  symbol: logSymbols.error,
44
51
  text: `Failed while rendering ${emailFilename}`,
45
52
  });
46
- return { error: result.error };
53
+ return { error: componentResult.error };
47
54
  }
48
55
 
49
56
  const {
@@ -51,7 +58,7 @@ export const renderEmailByPath = async (
51
58
  createElement,
52
59
  render,
53
60
  sourceMapToOriginalFile,
54
- } = result;
61
+ } = componentResult;
55
62
 
56
63
  const previewProps = Email.PreviewProps || {};
57
64
  const EmailComponent = Email as React.FC;
@@ -82,7 +89,7 @@ export const renderEmailByPath = async (
82
89
  text: `Successfully rendered ${emailFilename} in ${timeForConsole}`,
83
90
  });
84
91
 
85
- return {
92
+ const renderingResult = {
86
93
  // This ensures that no null byte character ends up in the rendered
87
94
  // markup making users suspect of any issues. These null byte characters
88
95
  // only seem to happen with React 18, as it has no similar incident with React 19.
@@ -90,6 +97,10 @@ export const renderEmailByPath = async (
90
97
  plainText,
91
98
  reactMarkup,
92
99
  };
100
+
101
+ cache.set(emailPath, renderingResult);
102
+
103
+ return renderingResult;
93
104
  } catch (exception) {
94
105
  const error = exception as Error;
95
106
 
@@ -16,7 +16,12 @@ export interface PreviewParams {
16
16
  slug: string[];
17
17
  }
18
18
 
19
- const Page = async ({ params }: { params: PreviewParams }) => {
19
+ const Page = async ({
20
+ params: paramsPromise,
21
+ }: {
22
+ params: Promise<PreviewParams>;
23
+ }) => {
24
+ const params = await paramsPromise;
20
25
  // will come in here as segments of a relative path to the email
21
26
  // ex: ['authentication', 'verify-password.tsx']
22
27
  const slug = decodeURIComponent(params.slug.join('/'));
@@ -43,14 +48,14 @@ This is most likely not an issue with the preview server. Maybe there was a typo
43
48
  throw exception;
44
49
  }
45
50
 
46
- const emailRenderingResult = await renderEmailByPath(emailPath);
51
+ const serverEmailRenderingResult = await renderEmailByPath(emailPath);
47
52
 
48
53
  if (
49
- 'error' in emailRenderingResult &&
50
- process.env.NEXT_PUBLIC_IS_BUILDING === 'true'
54
+ process.env.NEXT_PUBLIC_IS_BUILDING === 'true' &&
55
+ 'error' in serverEmailRenderingResult
51
56
  ) {
52
- throw new Error(emailRenderingResult.error.message, {
53
- cause: emailRenderingResult.error,
57
+ throw new Error(serverEmailRenderingResult.error.message, {
58
+ cause: serverEmailRenderingResult.error,
54
59
  });
55
60
  }
56
61
 
@@ -62,15 +67,20 @@ This is most likely not an issue with the preview server. Maybe there was a typo
62
67
  <Preview
63
68
  emailPath={emailPath}
64
69
  pathSeparator={path.sep}
65
- renderingResult={emailRenderingResult}
70
+ serverRenderingResult={serverEmailRenderingResult}
66
71
  slug={slug}
67
72
  />
68
73
  </Suspense>
69
74
  );
70
75
  };
71
76
 
72
- export function generateMetadata({ params }: { params: PreviewParams }) {
73
- return { title: `${path.basename(params.slug.join('/'))} — React Email` };
77
+ export async function generateMetadata({
78
+ params,
79
+ }: {
80
+ params: Promise<PreviewParams>;
81
+ }) {
82
+ const { slug } = await params;
83
+ return { title: `${path.basename(slug.join('/'))} — React Email` };
74
84
  }
75
85
 
76
86
  export default Page;
@@ -8,22 +8,22 @@ import type { EmailRenderingResult } from '../../../actions/render-email-by-path
8
8
  import { CodeContainer } from '../../../components/code-container';
9
9
  import { Shell } from '../../../components/shell';
10
10
  import { Tooltip } from '../../../components/tooltip';
11
- import { useEmails } from '../../../contexts/emails';
12
11
  import { useRenderingMetadata } from '../../../hooks/use-rendering-metadata';
12
+ import { useEmailRenderingResult } from '../../../hooks/use-email-rendering-result';
13
13
  import { RenderingError } from './rendering-error';
14
14
 
15
15
  interface PreviewProps {
16
16
  slug: string;
17
17
  emailPath: string;
18
18
  pathSeparator: string;
19
- renderingResult: EmailRenderingResult;
19
+ serverRenderingResult: EmailRenderingResult;
20
20
  }
21
21
 
22
22
  const Preview = ({
23
23
  slug,
24
24
  emailPath,
25
25
  pathSeparator,
26
- renderingResult: initialRenderingResult,
26
+ serverRenderingResult,
27
27
  }: PreviewProps) => {
28
28
  const router = useRouter();
29
29
  const pathname = usePathname();
@@ -31,17 +31,16 @@ const Preview = ({
31
31
 
32
32
  const activeView = searchParams.get('view') ?? 'desktop';
33
33
  const activeLang = searchParams.get('lang') ?? 'jsx';
34
- const { useEmailRenderingResult } = useEmails();
35
34
 
36
35
  const renderingResult = useEmailRenderingResult(
37
36
  emailPath,
38
- initialRenderingResult,
37
+ serverRenderingResult,
39
38
  );
40
39
 
41
40
  const renderedEmailMetadata = useRenderingMetadata(
42
41
  emailPath,
43
42
  renderingResult,
44
- initialRenderingResult,
43
+ serverRenderingResult,
45
44
  );
46
45
 
47
46
  if (process.env.NEXT_PUBLIC_IS_BUILDING !== 'true') {
@@ -90,7 +89,6 @@ const Preview = ({
90
89
  <RenderingError error={renderingResult.error} />
91
90
  ) : null}
92
91
 
93
- {/* If this is undefined means that the initial server render of the email had errors */}
94
92
  {hasNoErrors ? (
95
93
  <>
96
94
  {activeView === 'desktop' && (
@@ -135,6 +133,7 @@ const Preview = ({
135
133
  )}
136
134
  </>
137
135
  ) : null}
136
+
138
137
  <Toaster />
139
138
  </div>
140
139
  </Shell>
@@ -1,26 +1,14 @@
1
1
  'use client';
2
- import { createContext, useContext, useEffect, useState } from 'react';
2
+ import { createContext, useContext, useState } from 'react';
3
3
  import {
4
4
  getEmailsDirectoryMetadata,
5
5
  type EmailsDirectory,
6
6
  } from '../actions/get-emails-directory-metadata';
7
7
  import { useHotreload } from '../hooks/use-hot-reload';
8
- import {
9
- renderEmailByPath,
10
- type EmailRenderingResult,
11
- } from '../actions/render-email-by-path';
12
- import { getEmailPathFromSlug } from '../actions/get-email-path-from-slug';
13
8
 
14
9
  const EmailsContext = createContext<
15
10
  | {
16
11
  emailsDirectoryMetadata: EmailsDirectory;
17
- /**
18
- * Uses the hot reloaded bundled build and rendering email result
19
- */
20
- useEmailRenderingResult: (
21
- emailPath: string,
22
- serverEmailRenderedResult: EmailRenderingResult,
23
- ) => EmailRenderingResult;
24
12
  }
25
13
  | undefined
26
14
  >(undefined);
@@ -44,14 +32,11 @@ export const EmailsProvider = (props: {
44
32
  const [emailsDirectoryMetadata, setEmailsDirectoryMetadata] =
45
33
  useState<EmailsDirectory>(props.initialEmailsDirectoryMetadata);
46
34
 
47
- const [renderingResultPerEmailPath, setRenderingResultPerEmailPath] =
48
- useState<Record<string, EmailRenderingResult>>({});
49
-
50
35
  if (process.env.NEXT_PUBLIC_IS_BUILDING !== 'true') {
51
36
  // this will not change on runtime so it doesn't violate
52
37
  // the rules of hooks
53
38
  // eslint-disable-next-line react-hooks/rules-of-hooks
54
- useHotreload(async (changes) => {
39
+ useHotreload(async () => {
55
40
  const metadata = await getEmailsDirectoryMetadata(
56
41
  props.initialEmailsDirectoryMetadata.absolutePath,
57
42
  );
@@ -62,28 +47,6 @@ export const EmailsProvider = (props: {
62
47
  'Hot reloading: unable to find the emails directory to update the sidebar',
63
48
  );
64
49
  }
65
-
66
- for await (const change of changes) {
67
- const slugForChangedEmail =
68
- // ex: apple-receipt.tsx
69
- // it will be the path relative to the emails directory, so it is already
70
- // going to be equivalent to the slug
71
- change.filename;
72
-
73
- const pathForChangedEmail =
74
- await getEmailPathFromSlug(slugForChangedEmail);
75
-
76
- const lastResult = renderingResultPerEmailPath[pathForChangedEmail];
77
-
78
- if (typeof lastResult !== 'undefined') {
79
- const renderingResult = await renderEmailByPath(pathForChangedEmail);
80
-
81
- setRenderingResultPerEmailPath((map) => ({
82
- ...map,
83
- [pathForChangedEmail]: renderingResult,
84
- }));
85
- }
86
- }
87
50
  });
88
51
  }
89
52
 
@@ -91,23 +54,6 @@ export const EmailsProvider = (props: {
91
54
  <EmailsContext.Provider
92
55
  value={{
93
56
  emailsDirectoryMetadata,
94
- useEmailRenderingResult: (emailPath, serverEmailRenderedResult) => {
95
- useEffect(() => {
96
- if (typeof renderingResultPerEmailPath[emailPath] === 'undefined') {
97
- setRenderingResultPerEmailPath((map) => ({
98
- ...map,
99
- [emailPath]: serverEmailRenderedResult,
100
- }));
101
- }
102
- }, [serverEmailRenderedResult, emailPath]);
103
-
104
- if (typeof renderingResultPerEmailPath[emailPath] !== 'undefined') {
105
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
106
- return renderingResultPerEmailPath[emailPath]!;
107
- }
108
-
109
- return serverEmailRenderedResult;
110
- },
111
57
  }}
112
58
  >
113
59
  {props.children}
@@ -0,0 +1,44 @@
1
+ import { useState } from 'react';
2
+ import {
3
+ renderEmailByPath,
4
+ type EmailRenderingResult,
5
+ } from '../actions/render-email-by-path';
6
+ import { getEmailPathFromSlug } from '../actions/get-email-path-from-slug';
7
+ import { useHotreload } from './use-hot-reload';
8
+
9
+ export const useEmailRenderingResult = (
10
+ emailPath: string,
11
+ serverEmailRenderedResult: EmailRenderingResult,
12
+ ) => {
13
+ const [renderingResult, setRenderingResult] = useState(
14
+ serverEmailRenderedResult,
15
+ );
16
+
17
+ if (process.env.NEXT_PUBLIC_IS_BUILDING !== 'true') {
18
+ // eslint-disable-next-line react-hooks/rules-of-hooks
19
+ useHotreload(async (changes) => {
20
+ for await (const change of changes) {
21
+ const slugForChangedEmail =
22
+ // ex: apple-receipt.tsx
23
+ // it will be the path relative to the emails directory, so it is already
24
+ // going to be equivalent to the slug
25
+ change.filename;
26
+
27
+ const pathForChangedEmail =
28
+ await getEmailPathFromSlug(slugForChangedEmail);
29
+
30
+ // We always render the email template here so that we can allow
31
+ const newRenderingResult = await renderEmailByPath(
32
+ pathForChangedEmail,
33
+ true,
34
+ );
35
+
36
+ if (pathForChangedEmail === emailPath) {
37
+ setRenderingResult(newRenderingResult);
38
+ }
39
+ }
40
+ });
41
+ }
42
+
43
+ return renderingResult;
44
+ };
@@ -16,19 +16,19 @@ const lastRenderingMetadataPerEmailPath = {} as Record<
16
16
  export const useRenderingMetadata = (
17
17
  emailPath: string,
18
18
  renderingResult: EmailRenderingResult,
19
- initialRenderingMetadata?: EmailRenderingResult,
19
+ serverRenderingMetadata: EmailRenderingResult,
20
20
  ): RenderedEmailMetadata | undefined => {
21
21
  useEffect(() => {
22
22
  if ('markup' in renderingResult) {
23
23
  lastRenderingMetadataPerEmailPath[emailPath] = renderingResult;
24
24
  } else if (
25
- typeof initialRenderingMetadata !== 'undefined' &&
26
- 'markup' in initialRenderingMetadata &&
25
+ typeof serverRenderingMetadata !== 'undefined' &&
26
+ 'markup' in serverRenderingMetadata &&
27
27
  typeof lastRenderingMetadataPerEmailPath[emailPath] === 'undefined'
28
28
  ) {
29
- lastRenderingMetadataPerEmailPath[emailPath] = initialRenderingMetadata;
29
+ lastRenderingMetadataPerEmailPath[emailPath] = serverRenderingMetadata;
30
30
  }
31
- }, [renderingResult, emailPath, initialRenderingMetadata]);
31
+ }, [renderingResult, emailPath, serverRenderingMetadata]);
32
32
 
33
33
  return 'error' in renderingResult
34
34
  ? lastRenderingMetadataPerEmailPath[emailPath]
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+
3
+ type BodyProps = Readonly<React.HtmlHTMLAttributes<HTMLBodyElement>>;
4
+ declare const Body: React.ForwardRefExoticComponent<Readonly<React.HtmlHTMLAttributes<HTMLBodyElement>> & React.RefAttributes<HTMLBodyElement>>;
5
+
6
+ export { Body, type BodyProps };
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+
3
+ type BodyProps = Readonly<React.HtmlHTMLAttributes<HTMLBodyElement>>;
4
+ declare const Body: React.ForwardRefExoticComponent<Readonly<React.HtmlHTMLAttributes<HTMLBodyElement>> & React.RefAttributes<HTMLBodyElement>>;
5
+
6
+ export { Body, type BodyProps };