From 74d49e528d41bcf22d023edbaaa01e3bd960b02f Mon Sep 17 00:00:00 2001 From: Gabriel Miranda Date: Wed, 13 Nov 2024 08:42:08 -0800 Subject: [PATCH] fix(react-email): Null byte characters being rendered in the preview (#1773) --- .changeset/clever-meals-vanish.md | 5 +++++ packages/react-email/src/actions/render-email-by-path.tsx | 5 ++++- packages/render/src/node/read-stream.ts | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/clever-meals-vanish.md diff --git a/.changeset/clever-meals-vanish.md b/.changeset/clever-meals-vanish.md new file mode 100644 index 0000000000..01f4c6d9bd --- /dev/null +++ b/.changeset/clever-meals-vanish.md @@ -0,0 +1,5 @@ +--- +"react-email": patch +--- + +fix null byte characters being rendered in the preview server diff --git a/packages/react-email/src/actions/render-email-by-path.tsx b/packages/react-email/src/actions/render-email-by-path.tsx index e020917d71..11fa54da33 100644 --- a/packages/react-email/src/actions/render-email-by-path.tsx +++ b/packages/react-email/src/actions/render-email-by-path.tsx @@ -83,7 +83,10 @@ export const renderEmailByPath = async ( }); return { - markup, + // This ensures that no null byte character ends up in the rendered + // markup making users suspect of any issues. These null byte characters + // only seem to happen with React 18, as it has no similar incident with React 19. + markup: markup.replaceAll('\0', ''), plainText, reactMarkup, }; diff --git a/packages/render/src/node/read-stream.ts b/packages/render/src/node/read-stream.ts index 8c24dcfe37..be7b04b412 100644 --- a/packages/render/src/node/read-stream.ts +++ b/packages/render/src/node/read-stream.ts @@ -29,10 +29,10 @@ export const readStream = async ( }); stream.pipe(writable); - return new Promise((resolve, reject) => { + await new Promise((resolve, reject) => { writable.on("error", reject); writable.on("close", () => { - resolve(result); + resolve(); }); }); }