-
Notifications
You must be signed in to change notification settings - Fork 750
Tailwind directives in generated HTML when safelist defined. Breaks styling in Gmail #1907
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
Comments
I want to work on this issue, Would you like to assign me? |
I wonder why you need to |
Looking at it, the way to go here is to just delete it from the config and warn that the no behavior change will happen because of |
We are building a design system for emails using react-email. Keeping in line with our design system for web, we provide props for specifying margin and padding. These props are converted into classes dynamically. Since we do not have the tailwind classes appearing as a single, unbroken string, the spacing classes do not get converted into inline styles unless we add them to the safelist. https://tailwindcss.com/docs/detecting-classes-in-source-files#dynamic-class-names Since a consumer of the design system could use any of the available spacing classes, we safelist all of them dynamically. We did not want to keep a list of all available spacing classes as that is quite verbose. I will update the code in my reproduction to demonstrate sometime today. |
@summer-jordan can you make a minmal code example of what you mean here? Because it seems to me like it would work without the |
@gabrielmfern I was able to finally test this out and everything seems to work as you described. I removed the |
Describe the Bug
When using a custom tailwind config with a safelist, and using responsive tailwind classes, the generated HTML has a style tag with tailwind directives. These directives are invalid CSS which would seem to cause gmail to ignore the style tag entirely.
The directives can be seen in the dev servers code preview pane and in the HTML files generated with the export command.
Dev server Preview
HTML file
When testing emails with an email testing service, some styling was not looking right in some gmail clients. After some debugging, I realized that styles defined in the style tag were only respected when I removed the tailwind directives.
The provided minimal reproduction has 2 emails, one using a custom tailwind config and another that uses the same tailwind config with a safelist added. I have also included the HTML files for both emails generated with the export command.
Which package is affected (leave empty if unsure)
@react-email/tailwind
Link to the code that reproduces this issue
https://github.com/summer-jordan/tw-directive-bug-repro/
To Reproduce
pnpm create email
Tailwind
componentmd:p-4
(This is required so that a style tag is created)Expected Behavior
There should be no tailwind directives in the HTML.
What's your node version? (if relevant)
22.14.0
The text was updated successfully, but these errors were encountered: