Skip to content

Conversation

@adamwathan
Copy link
Member

Resolves #14772.

This PR fixes an issue where utilities like ps-2 were sorted earlier in the generated CSS than px-3, causing ps-2 to not override px-3 as expected.

This happened because px-3 uses padding-left and padding-right, and ps-2 uses padding-inline-start, and in property-order.ts we sort those properties as follows:

  ...
  'padding',
  'padding-inline',
  'padding-block',
  'padding-inline-start',
  'padding-inline-end',
  'padding-top',
  'padding-right',
  'padding-bottom',
  'padding-left',
  ...

Since padding-left and padding-right both appear later than padding-inline-start, the px-3 utility is sorted later in the CSS since all of its properties are later in the sort order than all of properties in ps-2.

To fix this, I'm using our internal --tw-sort property to tell Tailwind to sort the px-3 utility as if it used padding-inline to ensure that it's sorted earlier in the CSS.

This PR applies this same fix for the padding utilities, scroll-margin utilities, and scroll-padding utilities. No changes have been made to the margin utilities because we were already handling this correctly there.

Here you can see that pl-2 overrides px-6 as you'd expect:

image

…and now with the change in this PR, ps-2 also overrides px-6 as you'd expect:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure I understand the changes in this file. Why was x and y swapped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a side effect of px-* and py-* not previously sorting based on padding-inline and padding-block respectively.

For individual sides we sort in TRBL order, so since top comes before right, py-* came before px-*.

Now that we sort based on inline and block, px-* comes first because inline is before block in our sort order.

This actually fixes an inconsistency where margin and padding utilities were sorted differently already because margin was already doing this and padding wasn't:

<!-- Currently -->
<div class="mx-3 my-2"></div>
<div class="py-2 px-3"></div>

<!-- After this PR -->
<div class="mx-3 my-2"></div>
<div class="px-3 py-2"></div>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah gotcha this makes sense 👍

@adamwathan
Copy link
Member Author

Going to merge this even with the test failures since they are an upstream problem unrelated to these changes.

@adamwathan adamwathan merged commit d643d79 into next Oct 24, 2024
@adamwathan adamwathan deleted the fix/sort-logical-properties-after-pairs branch October 24, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The ps-10 or pe-10 is not applied as expected because px-5 takes precedence.

3 participants