Skip to content

Fix migrating mt-[0px] to -mt-[0px] instead of the other way around #18154

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

Merged
merged 3 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Upgrade: Migrate deprecated `order-none` to `order-0` ([#18126](https://github.com/tailwindlabs/tailwindcss/pull/18126))
- Support Leptos `class:` attributes when extracting classes ([#18093](https://github.com/tailwindlabs/tailwindcss/pull/18093))
- Fix "Cannot read properties of undefined" crash on malformed arbitrary value ([#18133](https://github.com/tailwindlabs/tailwindcss/pull/18133))
- Upgrade: Migrate `-mt-[0px]` to `mt-[0px]` instead of the other way around ([#18154](https://github.com/tailwindlabs/tailwindcss/pull/18154))

## [4.1.7] - 2025-05-15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export function migrateArbitraryUtilities(

let spacingMultiplier = spacing.get(designSystem)?.get(value)

for (let root of designSystem.utilities.keys('functional')) {
for (let root of Array.from(designSystem.utilities.keys('functional')).sort(
// Sort negative roots after positive roots so that we can try
// `mt-*` before `-mt-*`. This is especially useful in situations where
// `-mt-[0px]` can be translated to `mt-[0px]`.
(a, z) => Number(a[0] === '-') - Number(z[0] === '-'),
)) {
// Try as bare value
for (let replacementCandidate of parseCandidate(designSystem, `${root}-${value}`)) {
yield replacementCandidate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',

// Migrate deprecated named values to bare values
['order-none', 'order-0'],

// `-0` should not be migrated to `0`.
//
// This used to be a bug that translate `mt-[0px]` into `-mt-[0px]` because
// `-mt-[0px]` translates to `margin-top: calc(0px * -1);` and therefore we
// handle the `0px * -1` case which translates to `0px` not `-0px`.
//
// This translation is actually fine, because now, we will prefer the
// non-negative version first so we can replace `-mt-[0px]` with `mt-[0px]`.
['mt-[0px]', 'mt-[0px]'],
['-mt-[0px]', 'mt-[0px]'],
])(testName, async (candidate, result) => {
if (strategy === 'with-variant') {
candidate = `focus:${candidate}`
Expand Down