mail-react: Reproduce Gmail dropping a mail's head CSS - #6226
Open
VPS-Ricky wants to merge 1 commit into
Open
Conversation
VPS-Ricky
force-pushed
the
mail-react/gmail-head-css-budget-reproduction
branch
3 times, most recently
from
August 21, 2026 09:42
485bab9 to
f6ff5f6
Compare
VPS-Ricky
marked this pull request as ready for review
August 21, 2026 09:42
VPS-Ricky
marked this pull request as draft
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
force-pushed
the
mail-react/gmail-head-css-budget-reproduction
branch
from
August 21, 2026 12:27
f6ff5f6 to
a1af2e1
Compare
VPS-Ricky
marked this pull request as ready for review
August 21, 2026 12:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Gmail counts the combined content of every
<style>in a message, and past16384characters it removes all of them, not only the excess.This limit is easy to reach because
registerStylescollects the CSS of a module when the module is imported, not when a mail renders.MjmlMailRootthen 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
registerStylesemits would fix most of this without changing a rule. The CSS is 41% whitespace: minifying it takes the branded mail from21066to12680characters, below the limit on its own. Merging the@mediablocks by condition, of which that mail emits 88 with 6 distinct conditions, takes it to10506, 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