Skip to content

mail-react: Reproduce Gmail dropping a mail's head CSS - #6226

Open
VPS-Ricky wants to merge 1 commit into
mainfrom
mail-react/gmail-head-css-budget-reproduction
Open

mail-react: Reproduce Gmail dropping a mail's head CSS#6226
VPS-Ricky wants to merge 1 commit into
mainfrom
mail-react/gmail-head-css-budget-reproduction

Conversation

@VPS-Ricky

@VPS-Ricky VPS-Ricky commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Gmail counts the combined content of every <style> in a message, and past 16384 characters it removes all of them, not only the excess.

This limit is easy to reach because registerStyles collects the CSS of a module when the module is imported, not when a mail renders. MjmlMailRoot then puts the whole registry into the head, so a theme with twelve text variants sends rules for all twelve even when the mail uses five.

The two stories send the same mail body with a different theme, one below the limit and one above it, so the difference is visible when both are sent to the same account. Each mail reports its own character count, and a probe line turns green only if the head CSS arrived.

Two changes to what registerStyles emits would fix most of this without changing a rule. The CSS is 41% whitespace: minifying it takes the branded mail from 21066 to 12680 characters, below the limit on its own. Merging the @media blocks by condition, of which that mail emits 88 with 6 distinct conditions, takes it to 10506, half the original. Beyond that, emitting only the text variants a mail renders would stop the head CSS growing with the size of the theme.


Task: https://vivid-planet.atlassian.net/browse/PHSB2C-13467

@VPS-Ricky VPS-Ricky self-assigned this Aug 21, 2026
@VPS-Ricky
VPS-Ricky force-pushed the mail-react/gmail-head-css-budget-reproduction branch 3 times, most recently from 485bab9 to f6ff5f6 Compare August 21, 2026 09:42
@VPS-Ricky
VPS-Ricky marked this pull request as ready for review August 21, 2026 09:42
@github-actions
github-actions Bot requested a review from VPS-Obi August 21, 2026 09:43
@VPS-Ricky
VPS-Ricky marked this pull request as draft August 21, 2026 11:59
@VPS-Ricky
VPS-Ricky removed the request for review from VPS-Obi August 21, 2026 11:59
Gmail counts the combined content of every `<style>` in a message, and
past `16384` characters it removes all of them, not only the excess.

This limit is easy to reach because `registerStyles` collects the CSS
of a module when the module is imported, not when a mail renders.
`MjmlMailRoot` then puts the whole registry into the head, so a theme
with twelve text variants sends rules for all twelve even when the mail
uses five.

The two stories send the same mail body with a different theme, one
below the limit and one above it, so the difference is visible when
both are sent to the same account. Each mail reports its own character
count, and a probe line turns green only if the head CSS arrived.

Two changes to what `registerStyles` emits would fix most of this
without changing a rule. The CSS is 41% whitespace: minifying it takes
the branded mail from `21066` to `12680` characters, below the limit on
its own. Merging the `@media` blocks by condition, of which that mail
emits 88 with 6 distinct conditions, takes it to `10506`, half the
original. Beyond that, emitting only the text variants a mail renders
would stop the head CSS growing with the size of the theme.
@VPS-Ricky
VPS-Ricky force-pushed the mail-react/gmail-head-css-budget-reproduction branch from f6ff5f6 to a1af2e1 Compare August 21, 2026 12:27
@VPS-Ricky
VPS-Ricky marked this pull request as ready for review August 21, 2026 12:29
@github-actions
github-actions Bot requested a review from VPS-Obi August 21, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants