Polyfill: Fall back to first color value when color-mix(…) contains unresolvable var(…)#17513
Merged
RobinMalfait merged 7 commits intomainfrom Apr 3, 2025
Merged
Conversation
b3d75b2 to 64a3444 Compare thecrypticace approved these changes Apr 3, 2025
philipp-spiess commented Apr 3, 2025
Comment on lines 1728 to 1718
| @supports (not (-webkit-appearance: -apple-pay-button)) or (contain-intrinsic-size: 1px) { | ||
| ::placeholder { | ||
| color: color-mix(in oklab, currentColor 50%, transparent); | ||
| color: currentColor; | ||
| @supports (color: color-mix(in lab, red, red)) { | ||
| color: color-mix(in oklab, currentColor 50%, transparent); | ||
| } | ||
| } |
Contributor Author
There was a problem hiding this comment.
This looks a bit silly because we already have an @supports query in preflight and now we chain another one but when you think about it, the first one only makes sure that Safari versions that crash are gated out. Older versions of Chrome/Firefox _that do not support color-mix(…) would still not have a default in that case so this is a small improvement maybe?
In the future we might be able to clean this up if we use a different pass for applying that polyfill that has access to the parent path and then we can bail if this is already inside an @supprots or so.
980326b to 903ba82 Compare … unresolvable `var(…)`
1a54575 to 30049fe Compare 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.
This PR further improves the
color-mix(…)polyfill to create a reasonable fallback if dynamic values that can not statically be resolved are used. This refers to either the use ofcurrentcoloror any variables that are not static theme variables.Here are two examples that now generate a reasonable fallback instead of not showing any color at all:
Test plan
<p className="text-shadow-lg/50 [--my-color:red] text-shadow-(color:--my-color)">shadow test</p>color-mix(…)will properly show a red shadow now albeit with 100% opacity: iOS 15.5 and Chrome 110var(…)var(…)being chained with no space by lightningcss: Chrome 111