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

fix(tailwind): inline shadow colors with an opacity as a plain rgb() - #3951

Open
Maliik-B wants to merge 1 commit into
resend:canaryfrom
Maliik-B:fix/tailwind-shadow-opacity-colors
Open

Maliik-B wants to merge 1 commit into
resend:canaryfrom
Maliik-B:fix/tailwind-shadow-opacity-colors

Conversation

@Maliik-B

@Maliik-B Maliik-B commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Related issue or discussion

Fixes #3950.

What this changes

The color-mix() conversion in sanitizeDeclarations moves into its own function, resolveDerivedColors, which sanitizeDeclarations still calls and makeInlineStylesFor now also runs on each value it resolved.

Inside it:

  • A literal percentage is multiplied into the alpha the color already has, so bg-[#ff000080]/50 gets one alpha (0.25098039215686274) instead of a fifth value.
  • It runs post-order, so a nested color-mix() with two literal percentages becomes one rgb().
  • A color-mix() whose percentage is still a variable, like var(--tw-shadow-alpha), is left for the inline step instead of getting the variable appended.
  • A new case converts oklab(from rgb(…) l a b / <percentage>), which Tailwind writes for the default color of shadow-lg/20, to rgb() with that percentage as the alpha. The same goes for inset-, text- and drop-shadow-*/NN.

The inline step is what fixes shadow colors. --tw-shadow-alpha is set per element (shadow-lg/20 sets 20%), so the percentage is only known there. shadow-red-500/40 now inlines rgb(251,44,54,0.4), shadow-lg/20 shadow-red-500/40 gives 0.08, and shadow-red-500 gives rgb(251,44,54) instead of 100%. Without the inline call, every colored shadow would stay a color-mix(). Sent to Gmail (web and Android), the output keeps the element's style.

The inline step runs only this function, not all of sanitizeDeclarations as the fallback branch above it does: the values it resolves have already been through the stylesheet pass, and the full pass cost about four times as much. As it is, it adds about 5 to 10% render time for colored shadows and none for other classes.

"works with shadows" now inlines rgb(85,85,85) instead of rgb(85,85,85,100%), the shadow case #3579 left out. No other existing test changes.

This and #3933 both touch makeInlineStylesFor (the declaration loop here, resolveValue there); it merges cleanly with #3933 and with #3937.

Not addressed
  • Colors that can't become rgb() when the email is built still leave a color-mix(), which Gmail strips with the element's other styles: current and transparent with an opacity (bg-current/40), and an opacity variable the element doesn't set (bg-red-500/(--o) with --o on a parent). For that last one this is a change: canary gave rgb(251,44,54,var(--o)), which loses only the color in Gmail. These go to one follow-up issue.
  • A named color in an arbitrary value (shadow-[0_0_4px_red]/50) still leaves oklab(from red …).
  • In <style> rules (hover:, md:), a var() fallback isn't converted, so variant shadows keep rgb(0 0 0 / 0.1) and oklab(from …); that reaches past shadows and gets its own issue.

Tests

  • sanitizeDeclarations: nested color-mix() opacities multiply into one alpha; a relative oklab() with a percentage alpha is converted and five near misses are left as written.
  • <Tailwind>: an alpha shadow color, a shadow color with an opacity under a shadow opacity, and an alpha background with an opacity come out as plain rgb(); shadow-lg/20 comes out as rgb(0,0,0,0.2).
  • They fail on canary. pnpm lint and pnpm typecheck pass; the package tests pass except two react-email CLI specs that fail on canary on Windows too.

AI disclosure: written with Claude's help. I reviewed the change and the tests before opening this.

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 shadow colors with an opacity modifier (shadow-red-500/40, shadow-lg/20) so they render as a plain rgb() in the element's inline style instead of a color-mix() function, which Gmail strips.

Bug Fixes

  • Extracts the color-mix() conversion from sanitizeDeclarations into resolveDerivedColors and runs it during the inline step, where per-element values like --tw-shadow-alpha are known.
  • Multiplies nested color-mix() opacities into a single alpha, so bg-[#ff000080]/50 no longer produces a fifth value.
  • Converts oklab(from rgb(...) l a b / <percentage>) — the form Tailwind emits for the default shadow color in shadow-lg/20 — into rgb() with that percentage as alpha.
  • Adds roughly 5–10% render time for colored shadows and none for other classes.
  • Colors that can't resolve to rgb() at build time, like transparent or current with an opacity, still leave a color-mix().

Written for commit 6b8c480. Summary will update on new commits.

View guided diff

@vercel

vercel Bot commented Nov 30, 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 Nov 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6b8c480

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: opacity on shadows inlines color-mix() or oklab(), and Gmail then drops the element's whole style

1 participant