react-email 3.0.4 → 3.0.6
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 +12 -0
- package/dist/cli/index.js +87 -92
- package/dist/cli/index.mjs +28 -20
- 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_1c3sgg +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 +7 -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/196.js +5 -0
- package/dist/preview/.next/server/chunks/300.js +13 -0
- package/dist/preview/.next/server/chunks/391.js +1 -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/Trk1e7GzgKOLunAXBDCy-/_buildManifest.js +1 -0
- package/dist/preview/.next/static/chunks/12-b9450aa0845e7574.js +1 -0
- package/dist/preview/.next/static/chunks/154-4202f86af36ccff4.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-a2901ed1c2c53661.js +1 -0
- package/dist/preview/.next/static/chunks/app/page-54a86772095e22e0.js +1 -0
- package/dist/preview/.next/static/chunks/app/preview/[...slug]/page-2bfad134b65ddd79.js +1 -0
- package/dist/preview/.next/static/chunks/framework-e7cae9cecd5c9ba2.js +1 -0
- package/dist/preview/.next/static/chunks/main-app-cd104297c6bcc87e.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 +21 -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-action.ts +19 -0
- package/src/actions/render-email-by-path.tsx +16 -5
- package/src/app/layout.tsx +1 -1
- package/src/app/preview/[...slug]/page.tsx +20 -10
- package/src/app/preview/[...slug]/preview.tsx +6 -7
- package/src/components/sidebar/sidebar-directory-children.tsx +1 -1
- package/src/components/sidebar/sidebar-directory.tsx +1 -1
- package/src/contexts/emails.tsx +5 -61
- package/src/hooks/use-email-rendering-result.ts +44 -0
- package/src/hooks/use-rendering-metadata.ts +5 -5
- package/src/{actions → utils}/get-emails-directory-metadata.spec.ts +2 -1
- package/src/{actions → utils}/get-emails-directory-metadata.ts +0 -1
- 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 → Trk1e7GzgKOLunAXBDCy-}/_ssgManifest.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// File: /home/gabriel/Projects/Resend/react-email.git/
|
|
1
|
+
// File: /home/gabriel/Projects/Resend/react-email.git/tertiary/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/
|
|
1
|
+
// File: /home/gabriel/Projects/Resend/react-email.git/tertiary/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.6",
|
|
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
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import type { EmailsDirectory } from '../utils/get-emails-directory-metadata';
|
|
4
|
+
import { getEmailsDirectoryMetadata } from '../utils/get-emails-directory-metadata';
|
|
5
|
+
|
|
6
|
+
export const getEmailsDirectoryMetadataAction = async (
|
|
7
|
+
absolutePathToEmailsDirectory: string,
|
|
8
|
+
keepFileExtensions = false,
|
|
9
|
+
isSubDirectory = false,
|
|
10
|
+
|
|
11
|
+
baseDirectoryPath = absolutePathToEmailsDirectory,
|
|
12
|
+
): Promise<EmailsDirectory | undefined> => {
|
|
13
|
+
return getEmailsDirectoryMetadata(
|
|
14
|
+
absolutePathToEmailsDirectory,
|
|
15
|
+
keepFileExtensions,
|
|
16
|
+
isSubDirectory,
|
|
17
|
+
baseDirectoryPath,
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -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
|
|
package/src/app/layout.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Metadata } from 'next';
|
|
2
2
|
import './globals.css';
|
|
3
|
-
import { getEmailsDirectoryMetadata } from '../actions/get-emails-directory-metadata';
|
|
4
3
|
import { emailsDirectoryAbsolutePath } from '../utils/emails-directory-absolute-path';
|
|
5
4
|
import { EmailsProvider } from '../contexts/emails';
|
|
5
|
+
import { getEmailsDirectoryMetadata } from '../utils/get-emails-directory-metadata';
|
|
6
6
|
import { inter } from './inter';
|
|
7
7
|
|
|
8
8
|
export const metadata: Metadata = {
|
|
@@ -2,10 +2,10 @@ import path from 'node:path';
|
|
|
2
2
|
import { Suspense } from 'react';
|
|
3
3
|
import { redirect } from 'next/navigation';
|
|
4
4
|
import { getEmailPathFromSlug } from '../../../actions/get-email-path-from-slug';
|
|
5
|
-
import { getEmailsDirectoryMetadata } from '../../../actions/get-emails-directory-metadata';
|
|
6
5
|
import { renderEmailByPath } from '../../../actions/render-email-by-path';
|
|
7
6
|
import { emailsDirectoryAbsolutePath } from '../../../utils/emails-directory-absolute-path';
|
|
8
7
|
import Home from '../../page';
|
|
8
|
+
import { getEmailsDirectoryMetadata } from '../../../utils/get-emails-directory-metadata';
|
|
9
9
|
import Preview from './preview';
|
|
10
10
|
|
|
11
11
|
export const dynamicParams = true;
|
|
@@ -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>
|
|
@@ -2,7 +2,7 @@ import { AnimatePresence, LayoutGroup, motion } from 'framer-motion';
|
|
|
2
2
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
|
3
3
|
import Link from 'next/link';
|
|
4
4
|
import { useSearchParams } from 'next/navigation';
|
|
5
|
-
import type { EmailsDirectory } from '../../
|
|
5
|
+
import type { EmailsDirectory } from '../../utils/get-emails-directory-metadata';
|
|
6
6
|
import { emailsDirectoryAbsolutePath } from '../../utils/emails-directory-absolute-path';
|
|
7
7
|
import { cn } from '../../utils';
|
|
8
8
|
import { IconFile } from '../icons/icon-file';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { cn } from '../../utils';
|
|
5
|
-
import { type EmailsDirectory } from '../../
|
|
5
|
+
import { type EmailsDirectory } from '../../utils/get-emails-directory-metadata';
|
|
6
6
|
import { Heading } from '../heading';
|
|
7
7
|
import { IconFolder } from '../icons/icon-folder';
|
|
8
8
|
import { IconFolderOpen } from '../icons/icon-folder-open';
|
package/src/contexts/emails.tsx
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { createContext, useContext,
|
|
3
|
-
import {
|
|
4
|
-
getEmailsDirectoryMetadata,
|
|
5
|
-
type EmailsDirectory,
|
|
6
|
-
} from '../actions/get-emails-directory-metadata';
|
|
2
|
+
import { createContext, useContext, useState } from 'react';
|
|
3
|
+
import { getEmailsDirectoryMetadataAction } from '../actions/get-emails-directory-metadata-action';
|
|
7
4
|
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';
|
|
5
|
+
import type { EmailsDirectory } from '../utils/get-emails-directory-metadata';
|
|
13
6
|
|
|
14
7
|
const EmailsContext = createContext<
|
|
15
8
|
| {
|
|
16
9
|
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
10
|
}
|
|
25
11
|
| undefined
|
|
26
12
|
>(undefined);
|
|
@@ -44,15 +30,12 @@ export const EmailsProvider = (props: {
|
|
|
44
30
|
const [emailsDirectoryMetadata, setEmailsDirectoryMetadata] =
|
|
45
31
|
useState<EmailsDirectory>(props.initialEmailsDirectoryMetadata);
|
|
46
32
|
|
|
47
|
-
const [renderingResultPerEmailPath, setRenderingResultPerEmailPath] =
|
|
48
|
-
useState<Record<string, EmailRenderingResult>>({});
|
|
49
|
-
|
|
50
33
|
if (process.env.NEXT_PUBLIC_IS_BUILDING !== 'true') {
|
|
51
34
|
// this will not change on runtime so it doesn't violate
|
|
52
35
|
// the rules of hooks
|
|
53
36
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
54
|
-
useHotreload(async (
|
|
55
|
-
const metadata = await
|
|
37
|
+
useHotreload(async () => {
|
|
38
|
+
const metadata = await getEmailsDirectoryMetadataAction(
|
|
56
39
|
props.initialEmailsDirectoryMetadata.absolutePath,
|
|
57
40
|
);
|
|
58
41
|
if (metadata) {
|
|
@@ -62,28 +45,6 @@ export const EmailsProvider = (props: {
|
|
|
62
45
|
'Hot reloading: unable to find the emails directory to update the sidebar',
|
|
63
46
|
);
|
|
64
47
|
}
|
|
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
48
|
});
|
|
88
49
|
}
|
|
89
50
|
|
|
@@ -91,23 +52,6 @@ export const EmailsProvider = (props: {
|
|
|
91
52
|
<EmailsContext.Provider
|
|
92
53
|
value={{
|
|
93
54
|
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
55
|
}}
|
|
112
56
|
>
|
|
113
57
|
{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]
|
|
@@ -4,7 +4,7 @@ import { getEmailsDirectoryMetadata } from './get-emails-directory-metadata';
|
|
|
4
4
|
test('getEmailsDirectoryMetadata on demo emails', async () => {
|
|
5
5
|
const emailsDirectoryPath = path.resolve(
|
|
6
6
|
__dirname,
|
|
7
|
-
'../../../../apps/demo/emails
|
|
7
|
+
'../../../../apps/demo/emails',
|
|
8
8
|
);
|
|
9
9
|
expect(await getEmailsDirectoryMetadata(emailsDirectoryPath)).toEqual({
|
|
10
10
|
absolutePath: emailsDirectoryPath,
|
|
@@ -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
|
],
|