From aa15964b28ab9858ac0055082741c2f95f20a920 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Wed, 27 Nov 2024 11:39:04 -0500 Subject: [PATCH] Use unitless line-heights for font-size variables (#15216) Safari has an [insane bug](https://github.com/tailwindlabs/tailwindcss/issues/15196) where if you register custom properties for gradient colors using the `""` type, you attempt to transition a gradient on an element, _and_ you set a font-size and line-height on that element that point to CSS variables defined using `rem` units, the element size changes and shifts the layout while the transition is happening: https://github.com/user-attachments/assets/46eefccf-8a12-4751-8a44-54e48c54cd06 This bug goes away if you use anything other than `rem` units for the line-height. So this PR changes all of our variables like `--text-3xl--line-height` to use unitless relative line-height values instead of fixed line-height values to workaround this bug. Not my favorite change but pretty low impact because you likely aren't going to reference those variables for much anyways. If Safari ever fixes this bug (which is still present as of Safari 18), it would be nice to swap these back to what they were. Fixes #15196. --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com> --- CHANGELOG.md | 2 ++ .../src/__snapshots__/index.test.ts.snap | 16 ++++++++-------- .../src/__snapshots__/index.test.ts.snap | 16 ++++++++-------- packages/tailwindcss/theme.css | 16 ++++++++-------- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84b7ecf39..de4851d7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,11 +19,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure `--spacing-*` variables take precedence over `--container-*` variables ([#15180](https://github.com/tailwindlabs/tailwindcss/pull/15180)) - Fix scanning classes delimited by tab characters ([#15169](https://github.com/tailwindlabs/tailwindcss/pull/15169)) - Ensure opacity modifiers and semi-transparent gradients render correctly by default in Safari ([#15201](https://github.com/tailwindlabs/tailwindcss/pull/15201)) +- Fix element size thrashing when transitioning gradients on elements with a defined font-size in Safari ([#15216](https://github.com/tailwindlabs/tailwindcss/pull/15216)) ### Changed - Interpolate gradients using OKLAB instead of OKLCH by default ([#15201](https://github.com/tailwindlabs/tailwindcss/pull/15201)) - Error when `layer(…)` in `@import` is not first in the list of functions/conditions ([#15109](https://github.com/tailwindlabs/tailwindcss/pull/15109)) +- Use unitless line-height values for font-size variables in default theme ([#15216](https://github.com/tailwindlabs/tailwindcss/pull/15216)) ## [4.0.0-beta.2] - 2024-11-22 diff --git a/packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap b/packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap index 4a2c10321..f5bed31af 100644 --- a/packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap +++ b/packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap @@ -271,21 +271,21 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = ` --container-7xl: 80rem; --container-prose: 65ch; --text-xs: .75rem; - --text-xs--line-height: 1rem; + --text-xs--line-height: calc(1 / .75); --text-sm: .875rem; - --text-sm--line-height: 1.25rem; + --text-sm--line-height: calc(1.25 / .875); --text-base: 1rem; - --text-base--line-height: 1.5rem; + --text-base--line-height: calc(1.5 / 1); --text-lg: 1.125rem; - --text-lg--line-height: 1.75rem; + --text-lg--line-height: calc(1.75 / 1.125); --text-xl: 1.25rem; - --text-xl--line-height: 1.75rem; + --text-xl--line-height: calc(1.75 / 1.25); --text-2xl: 1.5rem; - --text-2xl--line-height: 2rem; + --text-2xl--line-height: calc(2 / 1.5); --text-3xl: 1.875rem; - --text-3xl--line-height: 2.25rem; + --text-3xl--line-height: calc(2.25 / 1.875); --text-4xl: 2.25rem; - --text-4xl--line-height: 2.5rem; + --text-4xl--line-height: calc(2.5 / 2.25); --text-5xl: 3rem; --text-5xl--line-height: 1; --text-6xl: 3.75rem; diff --git a/packages/tailwindcss/src/__snapshots__/index.test.ts.snap b/packages/tailwindcss/src/__snapshots__/index.test.ts.snap index 29d9523a4..78e3eee55 100644 --- a/packages/tailwindcss/src/__snapshots__/index.test.ts.snap +++ b/packages/tailwindcss/src/__snapshots__/index.test.ts.snap @@ -270,21 +270,21 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using --container-7xl: 80rem; --container-prose: 65ch; --text-xs: .75rem; - --text-xs--line-height: 1rem; + --text-xs--line-height: calc(1 / .75); --text-sm: .875rem; - --text-sm--line-height: 1.25rem; + --text-sm--line-height: calc(1.25 / .875); --text-base: 1rem; - --text-base--line-height: 1.5rem; + --text-base--line-height: calc(1.5 / 1); --text-lg: 1.125rem; - --text-lg--line-height: 1.75rem; + --text-lg--line-height: calc(1.75 / 1.125); --text-xl: 1.25rem; - --text-xl--line-height: 1.75rem; + --text-xl--line-height: calc(1.75 / 1.25); --text-2xl: 1.5rem; - --text-2xl--line-height: 2rem; + --text-2xl--line-height: calc(2 / 1.5); --text-3xl: 1.875rem; - --text-3xl--line-height: 2.25rem; + --text-3xl--line-height: calc(2.25 / 1.875); --text-4xl: 2.25rem; - --text-4xl--line-height: 2.5rem; + --text-4xl--line-height: calc(2.5 / 2.25); --text-5xl: 3rem; --text-5xl--line-height: 1; --text-6xl: 3.75rem; diff --git a/packages/tailwindcss/theme.css b/packages/tailwindcss/theme.css index c46f037f2..7ae95968f 100644 --- a/packages/tailwindcss/theme.css +++ b/packages/tailwindcss/theme.css @@ -296,21 +296,21 @@ --container-prose: 65ch; --text-xs: 0.75rem; - --text-xs--line-height: 1rem; + --text-xs--line-height: calc(1 / 0.75); --text-sm: 0.875rem; - --text-sm--line-height: 1.25rem; + --text-sm--line-height: calc(1.25 / 0.875); --text-base: 1rem; - --text-base--line-height: 1.5rem; + --text-base--line-height: calc(1.5 / 1); --text-lg: 1.125rem; - --text-lg--line-height: 1.75rem; + --text-lg--line-height: calc(1.75 / 1.125); --text-xl: 1.25rem; - --text-xl--line-height: 1.75rem; + --text-xl--line-height: calc(1.75 / 1.25); --text-2xl: 1.5rem; - --text-2xl--line-height: 2rem; + --text-2xl--line-height: calc(2 / 1.5); --text-3xl: 1.875rem; - --text-3xl--line-height: 2.25rem; + --text-3xl--line-height: calc(2.25 / 1.875); --text-4xl: 2.25rem; - --text-4xl--line-height: 2.5rem; + --text-4xl--line-height: calc(2.5 / 2.25); --text-5xl: 3rem; --text-5xl--line-height: 1; --text-6xl: 3.75rem;