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

fix(tailwind): resolve var(--tw-*) fallbacks in <style> rules - #3954

Open
Maliik-B wants to merge 1 commit into
resend:canaryfrom
Maliik-B:fix/tailwind-shadow-fallbacks-in-style
Open

Maliik-B wants to merge 1 commit into
resend:canaryfrom
Maliik-B:fix/tailwind-shadow-fallbacks-in-style

Conversation

@Maliik-B

@Maliik-B Maliik-B commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Related issue or discussion

Fixes #3953.

What this changes

sanitizeNonInlinableRules now replaces each var(--tw-*, <fallback>) in the rules that go to the <style> with its fallback, run through sanitizeDeclarations, the way makeInlineStylesFor already treats fallbacks for inline styles (#3768). Nothing <Tailwind> writes can define those variables: this function already removes them from <style> rules (#3542), and inline styles never carry custom properties. So a client that resolves the var() always lands on the fallback anyway. User variables are left alone (--tw- only, the same scope as stripEmptyTailwindVars).

A variant shadow now writes rgb(0,0,0,0.1) instead of var(--tw-shadow-color, rgb(0 0 0 / 0.1)), and Gmail keeps the <style>. Gmail web, the issue's email built from this branch, where the md: box keeps its fill:

gmail-s-fixed-b-cropped

Of the 18,881 classes in Tailwind's class list, under md: 60 change and nothing else does: the 12 box and inset shadows; the 12 ring and inset-ring widths, whose var(--tw-ring-color, currentcolor) (or --tw-inset-ring-color) becomes currentcolor; and 36 mask utilities, whose var(--tw-mask-*-stops, var(--tw-mask-*-position)) becomes the inner variable. No existing test changes.

With #3951, hover:shadow-lg/20 comes out as rgb(0,0,0,0.2) too; without it the fallback is substituted but stays oklab(from …). This merges cleanly with #3933, #3937 and #3951.

Not addressed:

  • A shadow color under a variant still doesn't reach the <style>, as before this PR. Under md:, md:shadow-red-500's --tw-shadow-color is removed with the other --tw-* declarations (fix(tailwind): tw-* variables in non inlined rules #3542), so the shadow keeps the default color. Under hover: with tailwindcss 4.1.x (the lockfile's version), hover: rules pick up each other's variables, so hover:shadow-md hover:shadow-red-500 writes the color as a color-mix(), which Gmail also drops from a <style>; with 4.3.x nothing is picked up. That is also why the <Tailwind> test below uses md:.
  • Variant shadows still don't show in clients that keep the <style>: the bare var(--tw-inset-shadow) and the others in the same rule have no fallback, so the declaration is invalid (checked in Chromium, WebKit and Firefox). Fixing that means using Tailwind's registered initial values for every variant class with a bare var(), so it gets its own issue.

Tests

  • <Tailwind>: md:shadow-md md:inset-shadow-sm write rgb(0,0,0,0.1) and no whitespace rgb() in the <style>.
  • sanitizeNonInlinableRules: after a shadow, a ring and a mask (whose fallback is another variable) go through it, no var(--tw-*, …) is left, and the ring's var(--tw-ring-offset-width), which has no fallback, stays.
  • Both fail on canary. pnpm lint and pnpm typecheck pass. The package tests pass (react-email 419, render 110, ui 113, editor 573, web 36) except two react-email CLI specs that fail on canary on Windows too (export-esbuild-plugins, isUnderDirectory).

AI disclosure: written with Claude's help. I reviewed the change and the tests, and checked the fixed build in Gmail web.

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 Gmail dropping <style> rules that use shadows with variants like hover:shadow-md or md:shadow-lg.

sanitizeNonInlinableRules now replaces var(--tw-*, <fallback>) in <style> rules with the fallback, matching how inline styles already resolve fallbacks. Variant shadows now emit rgb(0,0,0,0.1) instead of var(--tw-shadow-color, rgb(0 0 0 / 0.1)).

  • Only --tw-* variables are substituted; user variables and var() calls without a fallback are untouched.
  • Shadow colors under a variant still don't reach the <style>, and variant shadows still don't render in clients that keep the <style>.

Written for commit bf13b20. Summary will update on new commits.

View guided diff

@vercel

vercel Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@Maliik-B 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 Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bf13b20

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 Dec 1, 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: a shadow under a variant (hover:shadow-md) makes Gmail drop the whole <style>

1 participant