Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview with 55+ characters causes blank email rendering in browser #1806

Open
Umbrien opened this issue Dec 7, 2024 · 3 comments
Open

Preview with 55+ characters causes blank email rendering in browser #1806

Umbrien opened this issue Dec 7, 2024 · 3 comments
Labels
Type: Bug Confirmed bug

Comments

@Umbrien
Copy link

Umbrien commented Dec 7, 2024

Describe the Bug

When string of <Preview> is longer than 55 characters, browser preview becomes a blank page.

Also, after making such a string, there appears two react minified console errors in this order: 418, 422. These errors do not disappear from browser console after fixing the preview, even after restarting dev server and reopening page in same browser instance.

React-email version: 3.0.3

Which package is affected (leave empty if unsure)

@react-email/preview

Link to the code that reproduces this issue

https://github.com/Umbrien/react-email-preview-bug-report

To Reproduce

Put a string longer than 55 characters in <Preview>

Expected Behavior

Preview does not cause errors

What's your node version? (if relevant)

20.12.0

@Umbrien Umbrien added the Type: Bug Confirmed bug label Dec 7, 2024
@Umbrien Umbrien changed the title Preview with 55+ character causes blank email rendering in browser Preview with 55+ characters causes blank email rendering in browser Dec 7, 2024
@Shriom-Trivedi
Copy link

Shriom-Trivedi commented Dec 9, 2024

Hi @Umbrien,

I did some digging and after hours of inspection I found something interesting, I'll put them below:

Issue Summary

The Preview component breaks the rendering of the component under certain conditions:

  1. When using {'a'.repeat(70)} inline in JSX, the component does not render.
  2. Using a variable (e.g., const previewText = 'b'.repeat(70)) or a literal string ("aaaaa...aaaa") works fine.
  3. The issue is related to how React processes inline JSX expressions, potentially causing unexpected behavior in the Preview component.

Root Cause

  1. renderWhiteSpace: The function appends invisible characters that may corrupt the DOM or interfere with sibling components, especially when combined with certain string manipulations.
  2. Inline String Evaluation: Inline expressions like {'a'.repeat(70)} undergo additional parsing, which might lead to encoding or rendering quirks in the Preview component's logic.

Recommendations & Fixes

  1. Normalize Input: Update the Preview component to robustly handle different forms of children input.
  2. Simplify renderWhiteSpace: Replace invisible characters with regular spaces or remove the function if unnecessary.

Note: On the other hand users might not use something like 'a'.repeat(50) but prevention better than cause I guess.

@Umbrien
Copy link
Author

Umbrien commented Dec 9, 2024

Thanks for your research @Shriom-Trivedi!

Actually, I got this error while using literals; I've used inline expression in the provided code just for clarity.
I've updated the repository with an email example that uses both variable and literal string, and the issue persists in both cases.

@Shriom-Trivedi
Copy link

Hi @Umbrien, @gabrielmfern

I might have a solution for this. This can be resolved by using simpler whitespaces in <Preiview /> component. I tested it with the solution and it seems to be working fine. I'm not really sure why the complex ones are being used.

@gabrielmfern if you confirm this, then I'll open the PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants