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> component's space characters are not being rendered properly on some email clients #609

Open
rretlaw opened this issue Mar 29, 2023 · 4 comments

Comments

@rretlaw
Copy link

rretlaw commented Mar 29, 2023

Describe the Bug

On rendering React Emails that are using the tag, I'm getting a large string of unreadable characters ([U+200E][U+200F]).

My setup is using CSS for formatting. I have each email created in seperate .jsx files and importing the components into a main MainEmail.jsx page for rendering and processing. In my preview, I do not see the unreadable characters as they show as regular spaces. (See below):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en"> <head data-id="__react-email-head"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <div id="__react-email-preview" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0"><strong>{{FirstName}}</strong>, An account on Martet has been created for you.<div> ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏ ‌​‍‎‏</div> </div> 

However, when the email is sent, the unreadable characters show up as [?]. Below is an example of the same text above where I copied the above text into a text document. I've attached a screenshot of Gmail where it shows the unreadable characters as well as VSCode showing the value of the characters.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en"> <head data-id="__react-email-head"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <div id="__react-email-preview" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0"><strong>{{FirstName}}</strong>, An account on Martet has been created for you.<div> ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏� ‌​‍‎‏�</div> </div> 

Setup: My app was built using Create React App and hasn't been migrated to Nextjs yet. Using Tailwind for CSS for the entire app. I installed the React Email components using npm inside VSCode into my larger project.

I installed all React Email components using the npm install @react-email/components -E commands vs. installing each component seperately. Therefore enabling me to import all with 1 import command vs. having seperate import commands for each component.

In terms of sending emails, I'm currently saving each rendered HTML file as a file on Azure and calling up the file via a backend process to fill in dynamic variables and the sending via C#. I do not yet have an operational Email provider as I'm looking to use Resend once C# becomes available.

I'm seeing this issue in the following email clients: Gmail Web, Yahoo Web, Outlook Web, Outlook Desktop (mac), Yahoo App for IPhone. If needed, I can provide more screenshots.

Render Command in React:

{render(subSection, {pretty: true}).replaceAll('[','{{').replaceAll(']','}}')}
  • I'm doing the bracket replacements for my dynamic variables. My back end process is currently using '{{' for the variable replacements but that gives react some fits so I use '[' in React to avoid any compile errors. I did confirm this issue exists regardless of the replace commands, meaning it's present when I render with the replace and without the replace.

Let me know if you need any additional info regarding configuration.

VSCode
gmail

Which package is affected (leave empty if unsure)

@react-email/preview

To Reproduce

Below is an example react email I'm building. I have separate components built for the Email Header and Footers but otherwise just straightforward React with Tailwind.

import * as React from 'react';
import {
  Body,
  Button,
  Container,
  Column,
  Head,
  Heading,
  Hr,
  Html,
  Img,
  Link,
  Preview,
  Row,
  Section,
  Tailwind,
  Text,
} from '@react-email/components';
import { MartetEmailHeader, BusinessEmailHeader } from './EmailHeader';
import { MartetFooter } from './MartetFooter';
import { BusinessFooter } from './BusinessFooter';

export function Information() {

    return (
    
        <Html>
        <Head />  
        <Preview>
            You have an update on your account.  
        </Preview>

        <Tailwind>
            <Section className="bg-white w-full max-w-[1080px] mx-auto my-auto text-gray-900 font-medium text-sm flex justify-center mt-4 ">
                <Container className='flex w-full max-w-[1080px] border border-solid border-gray-400 rounded rounded-lg overflow-hidden mx-auto'>

                    <MartetEmailHeader />
        
                    <Section className='p-4 w-full rounded-t-lg  w-full flex justify-left'>
                        <Text className='mb-2 flex justify-left'>
                            Hey <strong className="ml-2"> [FirstName]</strong>!
                        </Text>
                        <Text className='font-medium'>
                            [BodyText]
                        </Text>
                        <Text className='font-medium'>
                            Thanks,
                            Team Martet
                        </Text>
                    </Section>


                    <MartetFooter />

                </Container>
            </Section>

        </Tailwind>
        </Html>        
       
    );
  }

Expected Behavior

Expect the unreadable characters to not be present and thus in Email previews, it shouldn't show the ??????.

What's your node version? (if relevant)

v16.14.2

@rretlaw rretlaw added the Type: Bug Confirmed bug label Mar 29, 2023
@mkreuzmayr
Copy link
Contributor

mkreuzmayr commented Mar 30, 2023

I am not sure if this is connected to my problem, but after updating to the latest @react-email/preview I am not receiving mails in Outlook anymore. If I remove the Preview tag I receive them.

@chan-vince
Copy link

chan-vince commented May 11, 2023

I had this 'issue' but as far as I can tell, it's actually by design. They're invisible spaces, which is how a 'Preview' feature works - it adds these invisible spaces to stop the body of the email being drawn into the email preview area, e.g. in notifications.

Choosing which characters to use, that works across many email clients, is the challenge.

These characters don't seem to be compatible with AWS Cognito emails, so what I've done is do a sed find/replace in the email after exporting, replacing them with &#847;&zwnj;&nbsp;&#8199;&#65279; instead.

E.g. in python:

email = email.replace("\xa0\u200c\u200b\u200d\u200e\u200f\ufeff", "&#847;&zwnj;&nbsp;&#8199;&#65279;")

This has retained the Preview feature on the few clients I've tested (desktop Outlook, iOS Outlook app)

@b-bot
Copy link

b-bot commented May 18, 2023

I think we should escape all of these invisible characters for better compatibility with packages.
Like @chan-vince I also ran into issues when using Cognito lambda triggers as it violates the regex.

Can we maybe get an option in the render function to replace with escaped versions?

Here is a Typescript function that will help accomplish it in the meantime:

  const cleanHtml = (component: ReactElement) => {
    const emailHtml = render(component);
    const invisibleCharacters = {
      '\xa0': '&#847;', // NO-BREAK SPACE
      '\u200c': '&zwnj;', // ZERO WIDTH NON-JOINER
      '\u200b': '&#8199;', // ZERO WIDTH SPACE
      '\u200d': '&#8203;', // ZERO WIDTH JOINER
      '\u200e': '&#65279;', // LEFT-TO-RIGHT MARK
      '\u200f': '&#8207;', // RIGHT-TO-LEFT MARK
      '\ufeff': '&#65279;', // ZERO WIDTH NO-BREAK SPACE
    };
    return emailHtml.replace(
      /[\xa0\u200c\u200b\u200d\u200e\u200f\ufeff](?! )/g,
      (match) => {
        return invisibleCharacters[match];
      },
    );
  };

@gabrielmfern gabrielmfern changed the title <Preview> tag is placing [U+200E][U+200F] characters at the end of the </div> when rendering. <Preview> component's space characters are not being rendered properly on some email clients Mar 29, 2024
@gabrielmfern
Copy link
Collaborator

@rretlaw Could your issue be related to your font not supporting the characters we use for the white spaces? I've also tested this on Gmail but can't really replicate the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants