Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(tailwind): parse nested variant rules that do not start with & - #3948

Open
hsusul wants to merge 2 commits into
resend:canaryfrom
hsusul:fix/tailwind-nested-rules-without-leading-ampersand
Open

hsusul wants to merge 2 commits into
resend:canaryfrom
hsusul:fix/tailwind-nested-rules-without-leading-ampersand

Conversation

@hsusul

@hsusul hsusul commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Related issue or discussion

Fixes #3947

What this changes

css-tree only parses a nested rule in a style block when it starts with &. Tailwind v4 writes space-*, divide-*, *:, **: and in-* as nested rules that don't, such as :where(& > :not(:last-child)) and :where(*:focus) &. Those stayed unparsed Raw nodes, so the inliner dropped the class. Under a responsive variant, they went into <style> still nested.

getStyleSheet in setup-tailwind.ts now runs parseNestedRules on the parsed stylesheet. It re-parses each Raw child of a block as rules and swaps it in only when every result is a rule whose selectors all contain &. Any other Raw is left as it is today. After that, the existing non-inlinable path and the flattening from #3901 handle these rules like any other nested variant:

Class <style>
space-y-4 :where(.space-y-4>:not(:last-child)){margin-block-start:calc(1rem*0)!important;margin-block-end:calc(1rem*calc(1 - 0))!important}
*:p-2 :is(.__p-2>*){padding:0.5rem!important}
in-focus:p-2 :where(*:focus) .in-focus_p-2{padding:0.5rem!important}
sm:space-y-4 @media (min-width:40rem){:where(.sm_space-y-4>:not(:last-child)){...} }

#3593 tried to keep space-* and divide-* and was closed because the output stayed nested. This PR writes flat rules only, with the same :is() and :where() selectors that group-hover: and the #3901 flattening already produce.

This touches a different file from #3945, but the two interact. Arbitrary variants with & after an ancestor, like [.dark_&]:p-2 (.dark &), are dropped on canary. With this PR alone they are parsed, then inlined unconditionally as style="padding:0.5rem", which is the bug #3943 tracks for [&_p]:. With #3945 applied as well, they render .dark ._dark___p-2{padding:0.5rem!important}. Merging #3945 first avoids that. Both PRs add tests at the same spot in tailwind.spec.tsx, so the second one will need a small rebase.

Tests in tailwind.spec.tsx cover *:, **:, in-focus:, sm:*: and divide-[#f00]. All 5 fail on canary.

Verification on canary e1c0044a plus this branch:

  • vitest run src/components/tailwind in packages/react-email: 206 passed.
  • vitest run in packages/react-email: 422 passed, 2 failed. The failures are export-esbuild-plugins.spec.ts and the outDir with glob syntax case in export.spec.ts. They fail the same way on canary here: the first can't start pnpm, the second can't find css-tree.
  • biome check at the root: clean apart from one existing warning in apps/web/src/app/editor/editor-overrides.css.
  • tsc --noEmit in packages/react-email: no errors.
  • With fix(tailwind): keep nested selector variants out of inline styles #3945's two source files applied on top: vitest run src/components/tailwind passed, and [.dark_&]:p-2 rendered as above.

Not tested in any email client.

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.

Summary by cubic

Fixes Tailwind v4 classes like *:, **:, in-*, space-*, and divide-* being dropped from rendered emails. Under responsive variants they instead wrote nested CSS into <style>; these now render as flat rules too.

What changed

  • css-tree only parses nested rules that start with &, so these variants stayed as unparsed Raw nodes the inliner could not resolve.
  • getStyleSheet now runs parseNestedRules, which re-parses each Raw block child and swaps it in when every result is a rule whose selectors all contain &; anything else is left as-is.

Merge order

Written for commit 086383d. Summary will update on new commits.

View guided diff

@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@hsusul is attempting to deploy a commit to the resend Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 086383d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
react-email Patch
@react-email/editor Patch
@react-email/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tailwind: space-*, divide-*, *: and in-* classes are dropped, and leak nested CSS under sm:

1 participant