fix(render): strip NULL bytes from readStream output to prevent email truncation#2954
Open
yufeikang wants to merge 2 commits intoresend:canaryfrom
Open
fix(render): strip NULL bytes from readStream output to prevent email truncation#2954yufeikang wants to merge 2 commits intoresend:canaryfrom
yufeikang wants to merge 2 commits intoresend:canaryfrom
Conversation
🦋 Changeset detectedLatest commit: cccf6c3 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.
Author
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 Node render readStream output to prevent emails from being cut off when streaming multi‑byte UTF‑8 characters. Ensures non‑ASCII emails render fully in clients like Gmail.
Written for commit cccf6c3. Summary will update on new commits.