-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selection is broken in Chrome 131 due to --tw-text-opacity and friends #15000
Comments
This works around an issue in Chrome where `::selection` does not read from variables defined on `::selection` thus breaking all uses of color utilities with the selection variant. e.g. `selection::bg-red-200`. We now add a fallback value of `1` to all uses of `var(--tw-bg-opacity)`, `var(--tw-text-opacity)`, `var(--tw-border-opacity)`, etc… since Chrome treats the variable as if it did not exist because it's not defined on the parent. In Chrome 131 (until the change is rolled back) existing utilities like these will not work: - `selection:text-opacity-50` - `selection:[--tw-text-opacity:0.5]` Fixes #15000 --------- Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
Thanks for flagging this @schenney-chromium, we just released a patch to workaround this change in Chrome. Quick fix for all Tailwind users — as long as you aren't using any of the // tailwind.config.js
module.exports = {
future: {
disableColorOpacityUtilitiesByDefault: true
},
// ...
} This will work immediately, without having to upgrade Tailwind to the latest patch that we're tagging right now. This might be the best solution for the folks at The Verge because they are currently on Tailwind CSS v3.3 and might want to do more extensive testing before upgrading to v3.4 even though there should be no breaking changes. Alternate solution — replace any use of classes like - <div class="selection:bg-yellow-400">
+ <div class="selection:bg-yellow-400/100">
Lorem ipsum...
</div>
Tailwind has historically let you combine two classes to set the color of something and adjust the opacity of that color, so people have been able to do things like this: <p class="selection:bg-red-500 selection:bg-opacity-50">
Lorem ipsum...
</p> ...where the implementation of those classes was this: .selection\:bg-red-500::selection {
--tw-bg-opacity: 1;
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
}
.selection\:bg-opacity-50::selection {
--tw-bg-opacity: 0.5;
} So it's definitely has practical use, and has always worked fine in Chrome and still works in other browsers. Regardless we are pushing a patch now that adds a fallback like this: .selection\:bg-red-500 {
--tw-bg-opacity: 1;
background-color: rgb(239 68 68 / var(--tw-bg-opacity, 1));
} …but it does mean this sort of composition will no longer work in Chrome if variables defined on the There's an alternate solution for our users who do want to change the opacity which is to use a single class (this is what we recommend nowadays anyways): <p class="selection:bg-red-500/50">
Lorem ipsum...
</p> …but either way we need to ship this patch for even solid colors to work. One problem that is still going to exist because of this Chrome change is that selection backgrounds will still be invisible if someone writes this: <p class="bg-opacity-0 selection:bg-red-500 selection:bg-opacity-50">
Lorem ipsum...
</p> …since the |
v3.4.15 was released with a fix on our side for this 👍 |
Thanks for the fix. It's great to see you're already on top of it. Allowing and using custom variables that are defined in the selection block itself is something a least one other person has asked for. Maybe there is a reasonable way to implement it to at least solve the particular problem with your older version. I doubt that every site with an older version is going to update, and Safari will take a bit longer to ship this (not sure how long). |
What version of Tailwind CSS are you using?
Not sure what version sites are using, but I suspect less than a year old.
What build tool (or framework if it abstracts the build tool) are you using?
Don't know
What version of Node.js are you using?
Don't know
What browser are you using?
Chrome and Edge
What operating system are you using?
All
Reproduction URL
See https://issues.chromium.org/issues/378754060 for numerous reproductions. From The Verge:
All selection is blank in Chrome 131 and later on The Verge, Bloomberg news, ...
Describe your issue
Chrome 131 and browsers using Chromium enable CSS Highlight Inheritance for ::selection. In this model custom properties for ::selection and other highlight pseudos are taken from the originating element, and not the pseudo itself. All custom properties defined on highlight pseudos are ignored. But Tailwind defines a custom property for opacity on every use of a color, including ::selection colors. There is no practical use for this because the variable is redefined all over the place and any given usage inside ::selection applies only within that ::selection block (with the old behavior).
See https://developer.chrome.com/blog/selection-styling and https://blogs.igalia.com/schenney/css-custom-properties-in-highlight-pseudos/
I might try to figure out how to fix this and put up a PR for you.
The text was updated successfully, but these errors were encountered: