-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Improve compatibility with Safari 15 #17435
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
Conversation
cb15f4e
to
521c5ed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't functionally tested yet, but wanted to leave these notes already.
|
||
// Work around an issue where the media query range syntax transpilation | ||
// generates code that is invalid with `@media` queries level 3. | ||
out = out.replaceAll('@media not (', '@media not all and (') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
.text-red-500\\/\\(--my-half\\) { | ||
color: #fb2c3680; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sad that this means that you can't change the --my-half
value at runtime, but if it's not supported what can you do haha.
@@ -697,7 +708,7 @@ export async function compileAst( | |||
} | |||
|
|||
if (!utilitiesNode) { | |||
compiled ??= optimizeAst(ast, designSystem) | |||
compiled ??= optimizeAst(ast, designSystem, opts.polyfills) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should store the polyfills
on the designSystem
itself 🤔
…computation is just too flaky across OSes
…included in IntelliSense output
2ded17c
to
9244037
Compare
Sorry for the late comment, but it is my understanding that with this PR merged the general Safari support for basic Tailwind v4 goes from 16.4 to 16.2 ( |
This PR improves the compatibility with Tailwind CSS v4 with unsupported browsers with the goal to greatly improve compatibility with Safari 15.
To make this work, this PR makes the following changes to all code
oklab(…)
default theme values to use a percentage in the first place (so instead of--color-red-500: oklch(0.637 0.237 25.331);
we now define it as--color-red-500: oklch(63.7% 0.237 25.331);
since this syntax has much broader support on Safari).@property
with a@supports
query targeting older versions of Safari and Firefox *color-mix(…)
function that use inlined color values from your theme so that they can be computed a compile time bylightningcss
. These fallbacks will convert to srgb to increase compatibility.color-mix(…)
in case relative color is applied oncurrentcolor
(due to limited browser support)bg-linear-to-r/oklab
)@media
queries range syntax.A simplified example
Given this example CSS input:
Here's the updated output CSS including the newly added polyfills and updated
oklab
values:* A note on
@property
polyfills and CSS modulesOn Next.js, CSS module files are required to be pure, meaning that all selectors must either be scoped to a class or an ID. Fortunatnyl for us, this does not apply to
@property
rules which we've been using before to initialize CSS variables.However, since we're now bringing back the
@property
polyfills, that would cause unexpected rules to be exported from the CSS file as this:Would turn to the following file:
Notice that this adds a
*
selector which is not considered pure.Unfortunately there is no way for us to silence this warning or work around it, as the dependency causing this errors (
postcss-modules-local-by-default
) is bundled into Next.js. To work around crashes, these polyfills will not apply to CSS modules processed by the PostCSS extension for now.Testing on tailwindcss.com
To see the changes in effect, take a look at this screencast that compares tailwindcss.com on iOS 15.5 with a version that has the patches of this PR applied:
Screen.Recording.2025-03-28.at.17.52.25.mov
Open questions
@property
polyfill not require an@layer base
and instead place the generated CSS on the top of the file?@media
range query workaroundTest plan