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.
- package/CHANGELOG.md +6 -0
- package/dist/cli/index.js +90 -94
- package/dist/cli/index.mjs +69 -58
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +96 -0
- package/dist/index.mjs +21 -0
- package/dist/package/index.d.mts +33 -0
- package/dist/package/index.d.ts +33 -0
- package/dist/package/index.js +62 -0
- package/dist/package/index.mjs +7 -0
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/app-build-manifest.json +31 -31
- package/dist/preview/.next/app-path-routes-manifest.json +1 -1
- package/dist/preview/.next/build-manifest.json +14 -14
- package/dist/preview/.next/cache/.rscinfo +1 -1
- package/dist/preview/.next/cache/eslint/.cache_1vyas3k +1 -0
- package/dist/preview/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/preview/.next/diagnostics/framework.json +1 -1
- package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/preview/.next/next-server.js.nft.json +1 -1
- package/dist/preview/.next/prerender-manifest.json +1 -1
- package/dist/preview/.next/required-server-files.json +1 -1
- package/dist/preview/.next/server/app/_not-found/page.js +1 -1
- package/dist/preview/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/favicon.ico/route.js +1 -1
- package/dist/preview/.next/server/app/favicon.ico/route.js.nft.json +1 -1
- package/dist/preview/.next/server/app/page.js +1 -1
- package/dist/preview/.next/server/app/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page.js +6 -6
- package/dist/preview/.next/server/app/preview/[...slug]/page.js.nft.json +1 -1
- package/dist/preview/.next/server/app/preview/[...slug]/page_client-reference-manifest.js +1 -1
- package/dist/preview/.next/server/app-paths-manifest.json +1 -1
- package/dist/preview/.next/server/chunks/300.js +13 -0
- package/dist/preview/.next/server/chunks/420.js +1 -0
- package/dist/preview/.next/server/chunks/625.js +5 -0
- package/dist/preview/.next/server/chunks/631.js +6 -0
- package/dist/preview/.next/server/chunks/720.js +10 -0
- package/dist/preview/.next/server/middleware-build-manifest.js +1 -1
- package/dist/preview/.next/server/next-font-manifest.js +1 -1
- package/dist/preview/.next/server/next-font-manifest.json +1 -1
- package/dist/preview/.next/server/pages/500.html +1 -1
- package/dist/preview/.next/server/pages/_app.js +1 -1
- package/dist/preview/.next/server/pages/_app.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_document.js +1 -1
- package/dist/preview/.next/server/pages/_document.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_error.js +1 -1
- package/dist/preview/.next/server/pages/_error.js.nft.json +1 -1
- package/dist/preview/.next/server/server-reference-manifest.js +1 -1
- package/dist/preview/.next/server/server-reference-manifest.json +1 -1
- package/dist/preview/.next/static/6K68y2QEZ1dLbv-Xhi30p/_buildManifest.js +1 -0
- package/dist/preview/.next/static/chunks/12-b9450aa0845e7574.js +1 -0
- package/dist/preview/.next/static/chunks/154-69b91a0c2fd801b8.js +1 -0
- package/dist/preview/.next/static/chunks/447-886131c35ca42b91.js +1 -0
- package/dist/preview/.next/static/chunks/5fec7a0a-5179023f3f5a9421.js +1 -0
- package/dist/preview/.next/static/chunks/797-46f6c20952f0a280.js +2 -0
- package/dist/preview/.next/static/chunks/{677-dd9544a8249ca33a.js → 860-38d96c8819ba6f19.js} +1 -1
- package/dist/preview/.next/static/chunks/app/_not-found/page-96d3eac723be3ee2.js +1 -0
- package/dist/preview/.next/static/chunks/app/layout-e1b6f1534cbbe5bd.js +1 -0
- package/dist/preview/.next/static/chunks/app/page-2c3e297e38c526ef.js +1 -0
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-2b4988ba6daf34e1.js +1 -0
- package/dist/preview/.next/static/chunks/framework-e7cae9cecd5c9ba2.js +1 -0
- package/dist/preview/.next/static/chunks/main-app-2c7f96205a73f128.js +1 -0
- package/dist/preview/.next/static/chunks/main-df761fde212f9cda.js +1 -0
- package/dist/preview/.next/static/chunks/pages/_app-203a61b355820ccf.js +1 -0
- package/dist/preview/.next/static/chunks/pages/_error-1764ca54938748c8.js +1 -0
- package/dist/preview/.next/static/chunks/{webpack-08c76d9f8dd5b0f0.js → webpack-9255716c9496e606.js} +1 -1
- package/dist/preview/.next/static/css/{eecb5c96aca6bd9e.css → ec5d7e66bd3b6cb8.css} +1 -1
- package/dist/preview/.next/trace +20 -2
- package/dist/preview/.next/types/app/layout.ts +1 -1
- package/dist/preview/.next/types/app/preview/[...slug]/page.ts +1 -1
- package/dist/preview/.next/types/cache-life.d.ts +2 -0
- package/next-env.d.ts +1 -1
- package/package.json +6 -6
- package/src/actions/get-email-path-from-slug.ts +3 -2
- package/src/actions/get-emails-directory-metadata.spec.ts +1 -0
- package/src/actions/get-emails-directory-metadata.ts +62 -59
- package/src/actions/render-email-by-path.tsx +16 -5
- package/src/app/preview/[...slug]/page.tsx +19 -9
- package/src/app/preview/[...slug]/preview.tsx +6 -7
- package/src/contexts/emails.tsx +2 -56
- package/src/hooks/use-email-rendering-result.ts +44 -0
- package/src/hooks/use-rendering-metadata.ts +5 -5
- package/src/package/body/dist/index.d.mts +6 -0
- package/src/package/body/dist/index.d.ts +6 -0
- package/src/package/body/dist/index.js +79 -0
- package/src/package/body/dist/index.mjs +45 -0
- package/src/package/button/dist/index.d.mts +6 -0
- package/src/package/button/dist/index.d.ts +6 -0
- package/src/package/button/dist/index.js +252 -0
- package/src/package/button/dist/index.mjs +218 -0
- package/src/package/code-block/dist/index.d.mts +4906 -0
- package/src/package/code-block/dist/index.d.ts +4906 -0
- package/src/package/code-block/dist/index.js +18205 -0
- package/src/package/code-block/dist/index.mjs +18133 -0
- package/src/package/code-inline/dist/index.d.mts +11 -0
- package/src/package/code-inline/dist/index.d.ts +11 -0
- package/src/package/code-inline/dist/index.js +106 -0
- package/src/package/code-inline/dist/index.mjs +72 -0
- package/src/package/column/dist/index.d.mts +6 -0
- package/src/package/column/dist/index.d.ts +6 -0
- package/src/package/column/dist/index.js +79 -0
- package/src/package/column/dist/index.mjs +45 -0
- package/src/package/components/dist/index.d.mts +20 -0
- package/src/package/components/dist/index.d.ts +20 -0
- package/src/package/components/dist/index.js +62 -0
- package/src/package/components/dist/index.mjs +21 -0
- package/src/package/container/dist/index.d.mts +6 -0
- package/src/package/container/dist/index.d.ts +6 -0
- package/src/package/container/dist/index.js +93 -0
- package/src/package/container/dist/index.mjs +59 -0
- package/src/package/font/dist/index.d.mts +25 -0
- package/src/package/font/dist/index.d.ts +25 -0
- package/src/package/font/dist/index.js +55 -0
- package/src/package/font/dist/index.mjs +28 -0
- package/src/package/head/dist/index.d.mts +6 -0
- package/src/package/head/dist/index.d.ts +6 -0
- package/src/package/head/dist/index.js +83 -0
- package/src/package/head/dist/index.mjs +49 -0
- package/src/package/heading/dist/index.d.mts +43 -0
- package/src/package/heading/dist/index.d.ts +43 -0
- package/src/package/heading/dist/index.js +113 -0
- package/src/package/heading/dist/index.mjs +79 -0
- package/src/package/hr/dist/index.d.mts +6 -0
- package/src/package/hr/dist/index.d.ts +6 -0
- package/src/package/hr/dist/index.js +89 -0
- package/src/package/hr/dist/index.mjs +55 -0
- package/src/package/html/dist/index.d.mts +6 -0
- package/src/package/html/dist/index.d.ts +6 -0
- package/src/package/html/dist/index.js +79 -0
- package/src/package/html/dist/index.mjs +45 -0
- package/src/package/img/dist/index.d.mts +6 -0
- package/src/package/img/dist/index.d.ts +6 -0
- package/src/package/img/dist/index.js +94 -0
- package/src/package/img/dist/index.mjs +60 -0
- package/src/package/link/dist/index.d.mts +6 -0
- package/src/package/link/dist/index.d.ts +6 -0
- package/src/package/link/dist/index.js +90 -0
- package/src/package/link/dist/index.mjs +56 -0
- package/src/package/markdown/dist/index.d.mts +15 -0
- package/src/package/markdown/dist/index.d.ts +15 -0
- package/src/package/markdown/dist/index.js +92 -0
- package/src/package/markdown/dist/index.mjs +58 -0
- package/src/package/preview/dist/index.d.mts +12 -0
- package/src/package/preview/dist/index.d.ts +12 -0
- package/src/package/preview/dist/index.js +108 -0
- package/src/package/preview/dist/index.mjs +73 -0
- package/src/package/render/dist/browser/index.d.mts +24 -0
- package/src/package/render/dist/browser/index.d.ts +24 -0
- package/src/package/render/dist/browser/index.js +250 -0
- package/src/package/render/dist/browser/index.mjs +214 -0
- package/src/package/render/dist/index.d.mts +23 -0
- package/src/package/render/dist/index.d.ts +23 -0
- package/src/package/render/dist/index.js +768 -0
- package/src/package/render/dist/index.mjs +733 -0
- package/src/package/render/dist/node/index.d.mts +27 -0
- package/src/package/render/dist/node/index.d.ts +27 -0
- package/src/package/render/dist/node/index.js +212 -0
- package/src/package/render/dist/node/index.mjs +176 -0
- package/src/package/row/dist/index.d.mts +10 -0
- package/src/package/row/dist/index.d.ts +10 -0
- package/src/package/row/dist/index.js +93 -0
- package/src/package/row/dist/index.mjs +59 -0
- package/src/package/section/dist/index.d.mts +6 -0
- package/src/package/section/dist/index.d.ts +6 -0
- package/src/package/section/dist/index.js +93 -0
- package/src/package/section/dist/index.mjs +59 -0
- package/src/package/tailwind/dist/index.d.ts +19 -0
- package/src/package/tailwind/dist/index.js +48 -0
- package/src/package/tailwind/dist/index.mjs +17167 -0
- package/src/package/tailwind/dist/tailwindcss/config.d.ts +376 -0
- package/src/package/tailwind/dist/tailwindcss/generated/.gitkeep +0 -0
- package/src/package/tailwind/dist/tailwindcss/generated/colors.d.ts +298 -0
- package/src/package/tailwind/dist/tailwindcss/generated/corePluginList.d.ts +1 -0
- package/src/package/tailwind/dist/tailwindcss/generated/default-theme.d.ts +397 -0
- package/src/package/tailwind/dist/tailwindcss/index.d.ts +11 -0
- package/src/package/text/dist/index.d.mts +6 -0
- package/src/package/text/dist/index.d.ts +6 -0
- package/src/package/text/dist/index.js +89 -0
- package/src/package/text/dist/index.mjs +55 -0
- package/src/utils/types/hot-reload-event.ts +3 -6
- package/dist/preview/.next/cache/eslint/.cache_117y9un +0 -1
- package/dist/preview/.next/cache/webpack/client-production/1.pack +0 -0
- package/dist/preview/.next/cache/webpack/client-production/2.pack +0 -0
- package/dist/preview/.next/cache/webpack/client-production/index.pack.old +0 -0
- package/dist/preview/.next/cache/webpack/server-production/1.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/index.pack.old +0 -0
- package/dist/preview/.next/server/chunks/185.js +0 -1
- package/dist/preview/.next/server/chunks/270.js +0 -10
- package/dist/preview/.next/server/chunks/323.js +0 -4
- package/dist/preview/.next/server/chunks/867.js +0 -7
- package/dist/preview/.next/server/chunks/887.js +0 -5
- package/dist/preview/.next/server/chunks/931.js +0 -6
- package/dist/preview/.next/server/chunks/945.js +0 -13
- package/dist/preview/.next/static/chunks/131-f4d810c5beddfab6.js +0 -2
- package/dist/preview/.next/static/chunks/174-3e37f7e70124a32b.js +0 -1
- package/dist/preview/.next/static/chunks/406-3d68715e81289266.js +0 -1
- package/dist/preview/.next/static/chunks/41423bf1-6f7e6cd2fc1291c3.js +0 -1
- package/dist/preview/.next/static/chunks/968-7fddcc3bfb4ada61.js +0 -1
- package/dist/preview/.next/static/chunks/app/_not-found/page-53e238cd8965175e.js +0 -1
- package/dist/preview/.next/static/chunks/app/layout-94f263ae274f6f80.js +0 -1
- package/dist/preview/.next/static/chunks/app/page-68f0897ebaef4c9c.js +0 -1
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-823cfe936f21397d.js +0 -1
- package/dist/preview/.next/static/chunks/framework-9780ea70a2600e73.js +0 -1
- package/dist/preview/.next/static/chunks/main-app-d2690e9b3dbe4561.js +0 -1
- package/dist/preview/.next/static/chunks/main-f2abbba525af0515.js +0 -1
- package/dist/preview/.next/static/chunks/pages/_app-ac8e4ba1a8597f2e.js +0 -1
- package/dist/preview/.next/static/chunks/pages/_error-88e591eedab147f8.js +0 -1
- package/dist/preview/.next/static/yKpx8LQApEcHL50eu16RD/_buildManifest.js +0 -1
- /package/dist/preview/.next/static/{yKpx8LQApEcHL50eu16RD → 6K68y2QEZ1dLbv-Xhi30p}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// File: /home/gabriel/Projects/
|
|
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/
|
|
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/
|
|
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.
|
|
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": "
|
|
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.
|
|
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": "
|
|
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.
|
|
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.
|
|
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
|
+
});
|
|
@@ -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 =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
dirent.name,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
|
46
|
+
const componentResult = await getEmailComponent(emailPath);
|
|
40
47
|
|
|
41
|
-
if ('error' in
|
|
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:
|
|
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
|
-
} =
|
|
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
|
-
|
|
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 ({
|
|
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
|
|
51
|
+
const serverEmailRenderingResult = await renderEmailByPath(emailPath);
|
|
47
52
|
|
|
48
53
|
if (
|
|
49
|
-
'
|
|
50
|
-
|
|
54
|
+
process.env.NEXT_PUBLIC_IS_BUILDING === 'true' &&
|
|
55
|
+
'error' in serverEmailRenderingResult
|
|
51
56
|
) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
cause:
|
|
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
|
-
|
|
70
|
+
serverRenderingResult={serverEmailRenderingResult}
|
|
66
71
|
slug={slug}
|
|
67
72
|
/>
|
|
68
73
|
</Suspense>
|
|
69
74
|
);
|
|
70
75
|
};
|
|
71
76
|
|
|
72
|
-
export function generateMetadata({
|
|
73
|
-
|
|
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
|
-
|
|
19
|
+
serverRenderingResult: EmailRenderingResult;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const Preview = ({
|
|
23
23
|
slug,
|
|
24
24
|
emailPath,
|
|
25
25
|
pathSeparator,
|
|
26
|
-
|
|
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
|
-
|
|
37
|
+
serverRenderingResult,
|
|
39
38
|
);
|
|
40
39
|
|
|
41
40
|
const renderedEmailMetadata = useRenderingMetadata(
|
|
42
41
|
emailPath,
|
|
43
42
|
renderingResult,
|
|
44
|
-
|
|
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>
|
package/src/contexts/emails.tsx
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, useContext,
|
|
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 (
|
|
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
|
-
|
|
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
|
|
26
|
-
'markup' in
|
|
25
|
+
typeof serverRenderingMetadata !== 'undefined' &&
|
|
26
|
+
'markup' in serverRenderingMetadata &&
|
|
27
27
|
typeof lastRenderingMetadataPerEmailPath[emailPath] === 'undefined'
|
|
28
28
|
) {
|
|
29
|
-
lastRenderingMetadataPerEmailPath[emailPath] =
|
|
29
|
+
lastRenderingMetadataPerEmailPath[emailPath] = serverRenderingMetadata;
|
|
30
30
|
}
|
|
31
|
-
}, [renderingResult, emailPath,
|
|
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 };
|