fix: keep style attributes that aren't valid CSS instead of throwing - #674
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Closes #582
I ran the repro from the issue against current
master:Cannot read properties of undefined (reading 'indexOf')inresolveCSSVariablesdoesn't happen anymore, the CSS variables in that document (--mermaid-font-family) resolve fineCssSyntaxError: Unknown word undefined, with or withoutresolveCSSVariables. The input has 14style="undefined;;;undefined"attributes (generated by the Mermaid SVG rendering), and Juice parses existingstyleattributes strictly, so a single invalid one throws for the whole documentChange
Juice already keeps a
styleattribute as-is when template tags make it unparseable (#672). This extends that to anystyleattribute that isn't valid CSS: it's kept exactly as written, and the inlined declarations are put in front of it.That's what email clients and browsers do with invalid inline CSS anyway: ignore the bad parts and apply the rest. The attribute's own declarations still come last, so they still win over the stylesheet, same as when Juice merges them.
Behavior change
Invalid
styleattributes used to throw, now they're kept. The main one people hit is encoded quotes, like Chrome'sstyle="font-family: "Segoe UI""withoutdecodeStyleAttributes:(browsers decode the
", so the font still applies). Two existing tests asserted the throw and were updated. The tradeoffs: for an element whose ownstyleattribute is kept as-is, Juice can't merge/dedupe against it or derivewidth/heightattributes from sizes written in it. That only affects attributes that were already broken.The full repro from the issue now inlines fine, with and without
resolveCSSVariables.About removing
resolveCSSVariablesin favor ofpostcss-custom-properties, as suggested in the issue: I'd rather keep it, it works (including on that document) and can already be turned off.🤖 Generated with Claude Code