Skip to content

Commit

Permalink
fix: always generate all CSS rules before the others (#2223)
Browse files Browse the repository at this point in the history
  • Loading branch information
astahmer authored Feb 18, 2024
1 parent 60cace3 commit 8cd8c19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-flies-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/shared': patch
---

Always sort `all` to be first, so that other properties can easily override it
24 changes: 24 additions & 0 deletions packages/shared/__tests__/property-priority.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, test } from 'vitest'
import { getPropertyPriority } from '../src'

test('property priotity', () => {
expect(getPropertyPriority('all')).toMatchInlineSnapshot(`0`)
expect(getPropertyPriority('paddingTop')).toMatchInlineSnapshot(`2`)
expect(getPropertyPriority('background')).toMatchInlineSnapshot(`1`)
expect(getPropertyPriority('backgroundColor')).toMatchInlineSnapshot(`2`)
expect(getPropertyPriority('padding')).toMatchInlineSnapshot(`1`)

expect(
['backgroundColor', 'padding', 'background', 'all', 'paddingTop'].sort(
(a, b) => getPropertyPriority(a) - getPropertyPriority(b),
),
).toMatchInlineSnapshot(`
[
"all",
"padding",
"background",
"backgroundColor",
"paddingTop",
]
`)
})
1 change: 1 addition & 0 deletions packages/shared/src/shorthand-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,6 @@ const longhands = Object.values(shorthandProperties).reduce((a, b) => [...a, ...
* @see https://github.com/callstack/linaria/blob/049a4ccb77e29f3628353352db21bd446fa04a2e/packages/atomic/src/processors/helpers/propertyPriority.ts
*/
export function getPropertyPriority(property: string) {
if (property === 'all') return 0
return longhands.includes(property) ? 2 : 1
}

0 comments on commit 8cd8c19

Please sign in to comment.