Skip to content

Commit f43f1ce

Browse files
authored
feat(preview-server): separate timings for bundling/rendering (#2645)
1 parent f07f0ce commit f43f1ce

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

.changeset/honest-carrots-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-email/preview-server": patch
3+
---
4+
5+
show separate timings for bundling/rendering an email template

packages/preview-server/src/actions/render-email-by-path.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export const renderEmailByPath = async (
4949
return cache.get(emailPath)!;
5050
}
5151

52-
const timeBeforeEmailRendered = performance.now();
53-
5452
const emailFilename = path.basename(emailPath);
5553
let spinner: Ora | undefined;
5654
if (!isBuilding && !isPreviewDevelopment) {
@@ -61,6 +59,7 @@ export const renderEmailByPath = async (
6159
registerSpinnerAutostopping(spinner);
6260
}
6361

62+
const timeBeforeEmailBundled = performance.now();
6463
const originalJsxRuntimePath = path.resolve(
6564
previewServerLocation,
6665
'jsx-runtime',
@@ -70,6 +69,7 @@ export const renderEmailByPath = async (
7069
originalJsxRuntimePath,
7170
);
7271
const componentResult = await getEmailComponent(emailPath, jsxRuntimePath);
72+
const millisecondsToBundled = performance.now() - timeBeforeEmailBundled;
7373

7474
if ('error' in componentResult) {
7575
spinner?.stopAndPersist({
@@ -90,6 +90,7 @@ export const renderEmailByPath = async (
9090
const previewProps = Email.PreviewProps || {};
9191
const EmailComponent = Email as React.FC;
9292
try {
93+
const timeBeforeEmailRendered = performance.now();
9394
const element = createElement(EmailComponent, previewProps);
9495
const markupWithReferences = await renderWithReferences(element, {
9596
pretty: true,
@@ -117,7 +118,7 @@ export const renderEmailByPath = async (
117118
}
118119
spinner?.stopAndPersist({
119120
symbol: logSymbols.success,
120-
text: `Successfully rendered ${emailFilename} in ${timeForConsole}`,
121+
text: `Successfully rendered ${emailFilename} in ${timeForConsole} (bundled in ${millisecondsToBundled.toFixed(0)}ms)`,
121122
});
122123

123124
const renderingResult: RenderedEmailMetadata = {

0 commit comments

Comments
 (0)