Skip to content

Commit

Permalink
fix: sort rules right before generating the CSS (#2035)
Browse files Browse the repository at this point in the history
* fix: sort rules right before generating the CSS

we used to sort in the StyleDecoder only, and that lead to `this.atomic` sometimes not being fully sorted when generating the CSS: since it’s a Set, if an item was already there it would not be added again and this could mess with the order

* chore: add changeset
  • Loading branch information
astahmer authored Jan 19, 2024
1 parent f93d428 commit 9d000dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-pans-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@pandacss/core': patch
---

Fix a regression with rule insertion order after triggering HMR that re-uses some CSS already generated in previous
triggers, introuced in v0.27.0
8 changes: 4 additions & 4 deletions packages/core/__tests__/rule-processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,6 @@ describe('rule processor', () => {
color: var(--colors-blue-300);
}
.hover\\\\:text_red\\\\.400:is(:hover, [data-hover]) {
color: var(--colors-red-400);
}
.fs_12px {
font-size: 12px;
}
Expand All @@ -775,6 +771,10 @@ describe('rule processor', () => {
.border_2px_solid_token\\\\(colors\\\\.green\\\\.100\\\\) {
border: 2px solid var(--colors-green-100);
}
.hover\\\\:text_red\\\\.400:is(:hover, [data-hover]) {
color: var(--colors-red-400);
}
}"
`)
})
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { serializeStyles } from './serialize'
import { stringify } from './stringify'
import type { StyleDecoder } from './style-decoder'
import type { CssOptions, LayerName, ProcessOptions, StylesheetContext } from './types'
import { sortStyleRules } from './sort-style-rules'

export class Stylesheet {
constructor(private context: StylesheetContext) {}
Expand Down Expand Up @@ -52,7 +53,7 @@ export class Stylesheet {
}

processDecoder = (decoder: StyleDecoder) => {
decoder.atomic.forEach((css) => {
sortStyleRules([...decoder.atomic]).forEach((css) => {
this.processCss(css.result, (css.layer as LayerName) ?? 'utilities')
})

Expand Down

3 comments on commit 9d000dc

@vercel
Copy link

@vercel vercel bot commented on 9d000dc Jan 19, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

panda-docs – ./website

panda-docs-git-main-chakra-ui.vercel.app
panda-docs.vercel.app
panda-css.com
panda-docs-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 9d000dc Jan 19, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

panda-studio – ./

panda-app.vercel.app
panda-studio-git-main-chakra-ui.vercel.app
panda-studio-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 9d000dc Jan 19, 2024

Choose a reason for hiding this comment

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

Please sign in to comment.