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

Draft
PL
6d ago
+196-48

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 #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