Skip to content

fix(react-email): plain spaces in CodeBlock, keeping the Spark Mail fix - #3923

Draft
platoresend wants to merge 2 commits into
canaryfrom
fix/code-block-plain-spaces
Draft

platoresend wants to merge 2 commits into
canaryfrom
fix/code-block-plain-spaces

Conversation

@platoresend

@platoresend platoresend commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Related issue or discussion

Fixes code copied out of CodeBlock while keeping the Spark Mail fix from #2631.

What this changes

CodeBlock rendered every space as U+00A0 U+200D U+200B (NBSP + zero-width joiner + zero-width space). This was the #2631 workaround for Spark Mail, which drops <span>s that hold only whitespace. Side effect: recipients who copy npm install resend from an email paste invisible characters into their terminal, and the command fails.

Now CodeBlock renders plain spaces, and it never renders a <span> that holds only whitespace. Each whitespace token wraps the token after it (or the one before it, at the end of a line):

<!-- before -->
<span>npm</span><span>&nbsp;&zwj;&#8203;</span><span>install</span>
<!-- after -->
<span>npm</span><span> <span>install</span></span>

Text and per-character styles do not change. The only whitespace-only <span> left is a line that is all whitespace. If a client drops it, the line still shows as an empty line. The editor's ENCODED_SPACE_REGEX decode stays, so HTML exported before this change still imports with plain spaces.

Verification

  • New code-block.spec.tsx, run for all 400 Prism languages with 9 samples each (indentation, tabs, trailing spaces):
    • the HTML has no invisible characters, and the <pre> text equals the source,
    • no <span> holds only whitespace, and the text is unchanged after dropping such spans (the feat(code-block): deal with spark mail #2631 Spark behavior).
    • On canary: 793 of 801 tests fail. With plain spaces only: 348 Spark tests fail. With this PR: 801 pass.
  • Style check (local script, not committed): 38 themes × 400 languages × 7 samples. Every character has the same text and the same resolved styles as the plain-space markup: 0 differences in 6.6M characters.
  • Headless Chrome 145: screenshots of all 38 themes are byte-identical to the plain-space markup. A real Ctrl+C copy gives exactly the source text. The same copy on canary gives U+200D/U+200B after every space.
  • Updated the editor code-block.spec.tsx snapshot. react-email components: 1141 tests pass. editor: 552 pass. tsc and Biome clean.

Not verified yet: rendering in Spark Mail itself, and in Gmail, Outlook and Apple Mail.

Checklist

  • I understand the code in this PR and the problem it solves.
  • I read this description, and it accurately describes the change.
  • I added a changeset, or this change doesn't affect a published package.

Opened on behalf of: @vcapretz

CodeBlock replaced every space with NBSP + ZWJ + ZWSP (Spark Mail
workaround from #2631). Code copied from an email then failed in a
terminal. Render token text as-is; <pre> keeps the whitespace.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
react-email Ready Ready Preview Nov 18, 2026 3:16pm UTC
react-email-demo Ready Ready Preview Nov 18, 2026 3:16pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@react-email/editor@3923
npm i https://pkg.pr.new/react-email@3923

commit: 1ca9203

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Spark Mail drops <span>s that hold only whitespace (#2631). Instead of
encoding every space, never render a whitespace-only span: each
whitespace token wraps the token next to it. Text and styles stay the
same.
@platoresend platoresend changed the title fix(react-email): render plain spaces in CodeBlock fix(react-email): plain spaces in CodeBlock, keeping the Spark Mail fix Nov 18, 2026
@platoresend
platoresend requested a review from vcapretz November 18, 2026 15:14
@platoresend
platoresend marked this pull request as draft November 18, 2026 15:14
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1ca9203

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
react-email Patch
@react-email/editor Patch
@react-email/ui Patch

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Fixes CodeBlock copy-paste by replacing invisible characters with plain spaces and nested spans, but actual rendering in Spark Mail, Gmail, Outlook, and Apple Mail is explicitly unverified, so the email-client compatibility tradeoff needs human sign-off.

View guided diff | Re-trigger cubic

This branch was successfully deployed

2 active deployments
Preview – react-email-demo — 1ca92037 Deployed Nov 18, 2026 by vercel[bot]
Preview – react-email — 1ca92037 Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant