Repository navigation
Description
What versions are you using? (if relevant)
react-email 6.11.17, canary e1c0044a.
Describe the Bug
Inside <Tailwind>, space-*, divide-*, *:, **: and in-* classes vanish from the rendered email. The class is removed from the element, nothing is inlined, and nothing is written to <style>.
| Class | Rendered on canary |
|---|---|
space-y-4, space-x-2 |
<div>, empty <style> |
divide-y, divide-red-500 |
<div>, empty <style> |
*:p-2, **:p-2 |
<div>, empty <style> |
in-focus:p-2, in-data-active:p-2, in-[.dark]:p-2 |
<div>, empty <style> |
Behind a responsive variant the class survives, but its rule goes into <style> still nested, with var(--spacing) unresolved. This is sm:space-y-4:
@media (min-width:40rem){.sm_space-y-4{:where(& > :not(:last-child)) {
--tw-space-y-reverse: 0;
margin-block-start: calc(calc(var(--spacing) * 4) * var(--tw-space-y-reverse));
margin-block-end: calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-y-reverse)));
} } }md:divide-y and sm:*:underline do the same. #3901 found that Gmail drops the whole <style> when it holds a rule nested inside another rule. If that holds here, one sm:space-y-4 takes every responsive and dark-mode rule in the email down with it. I haven't tested this in Gmail.
Tailwind v4 writes these as nested rules that don't start with &. space-* and divide-* use :where(& > :not(:last-child)), *: uses :is(& > *), and in-focus: uses :where(*:focus) &. css-tree 3.2.1 only parses a nested rule in a style block when it starts with & (lib/syntax/node/Block.js) and keeps anything else as an unparsed Raw node. isRuleInlinable can't see into the Raw, so it calls the rule inlinable, makeInlineStylesFor finds no declarations, and the class is removed. Under sm:, downlevelForEmailClients only flattens parsed Rule and Atrule nodes, so the Raw stays nested.
#3593 reported the space-* and divide-* part in June. It was closed because its fix kept the nested CSS, which most email clients don't support. Since #3901, nested rules can be flattened, so these could be written as flat selectors.
Affected: Tailwind Component.
Link to the code that reproduces this issue
import { Body, Head, Html, render, Tailwind } from 'react-email';
const html = await render(
<Tailwind>
<Html>
<Head />
<Body>
<div className="space-y-4">
<p>one</p>
<p>two</p>
</div>
</Body>
</Html>
</Tailwind>,
);To Reproduce
- Check out canary
e1c0044a. - Render the template above, then try
sm:space-y-4and the other classes from the table. - Look at the
<div>and the<style>tag.
Expected Behavior
The class stays on the element and gets a flat rule in <style>, the way other variants already do:
:where(.space-y-4>:not(:last-child)){margin-block-start:calc(1rem*0)!important;margin-block-end:calc(1rem*calc(1 - 0))!important}What's your node version? (if relevant)
v24.9.0
Activity