fix(render): strip NULL bytes from readStream output to prevent email truncation#2954
fix(render): strip NULL bytes from readStream output to prevent email truncation#2954yufeikang wants to merge 3 commits intoresend:canaryfrom
Conversation
🦋 Changeset detectedLatest commit: 704af34 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@yufeikang is attempting to deploy a commit to the resend Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
fb42e8b to
adb71c7
Compare
Fixes the readStream output by stripping NULL bytes to prevent email truncation.
CI Test Failures — Not Related to This PRThe 2 snapshot test failures are caused by Evidence that this is unrelated to our changes:
The failing tests:
These will continue to fail on any PR until the snapshots on |
| "@react-email/render": patch | ||
| --- | ||
|
|
||
| fix(render): strip NULL bytes from readStream output to prevent email truncation |
There was a problem hiding this comment.
| fix(render): strip NULL bytes from readStream output to prevent email truncation | |
| strip NULL bytes from readStream output to prevent email truncation |
| // Strip NULL bytes (U+0000) that can appear when React's streaming renderer | ||
| // produces chunks that split multi-byte UTF-8 characters at chunk boundaries. | ||
| // The pretty() function already does this, but the default non-pretty path did not. | ||
| return result.replaceAll('\0', ''); |
There was a problem hiding this comment.
since we're doing this here now, can you remove it from the other places and just have it cenrtralized here?
| ); | ||
| }); | ||
|
|
||
| /** |
There was a problem hiding this comment.
you've misplaced the test after this comment here
Summary
readStream()in the Node.js render path can produce NULL bytes (U+0000) in the output when React's streaming renderer splits chunks at multi-byte UTF-8 character boundaries. Email clients (Gmail, etc.) treat NULL as a string terminator, causing emails to be silently truncated mid-content.Problem
The Node.js
readStream()usesTextDecoderwith{ stream: true }to decode chunks from React's streaming renderer (renderToReadableStream/renderToPipeableStream). When multi-byte UTF-8 characters (Japanese, German umlauts, Cyrillic, etc.) happen to span chunk boundaries, NULL bytes appear in the decoded string.The
pretty()function already handles this withstr.replaceAll("\0", "")(source), but the default (non-pretty) render path returns the result without stripping NULLs.Impact: Emails containing non-ASCII text are randomly truncated depending on where chunk boundaries fall. The browser version of
readStreamis not affected because it collects all chunks first and decodes them in a single pass.Related Issues
Ü→\ufffd) in generated HTMLFix
Strip NULL bytes from the
readStream()return value — same approach aspretty()already uses.Test
Added a regression test that renders a large template with Japanese, German, Russian, and Korean multi-byte characters and asserts no NULL bytes appear in the output.
Summary by cubic
Strip NULL bytes from the Node readStream to prevent truncation when streaming multi‑byte UTF‑8 characters. Ensures non‑ASCII emails render fully in clients like Gmail.
Written for commit 704af34. Summary will update on new commits.