Skip to content

Commit eff0866

Browse files
authored
fix(postcss): incorrect order of breakpoints (#3064)
1 parent bccd4fd commit eff0866

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

packages/postcss/src/apply.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export async function parseApply(root: Root, uno: UnoGenerator, directiveName: s
3636
if (!utils.length)
3737
return
3838

39+
const parentAfterNodes: Root[] = []
40+
3941
for (const i of utils) {
4042
const [, _selector, body, parent] = i
4143
const selector = _selector?.replace(regexScopePlaceholder, ' ') || _selector
@@ -71,7 +73,7 @@ export async function parseApply(root: Root, uno: UnoGenerator, directiveName: s
7173
css_parsed.walkDecls((declaration) => {
7274
declaration.source = source
7375
})
74-
rule.parent.after(css_parsed)
76+
parentAfterNodes.push(css_parsed)
7577
}
7678
else {
7779
const css = postcss.parse(body)
@@ -81,7 +83,7 @@ export async function parseApply(root: Root, uno: UnoGenerator, directiveName: s
8183
rule.parent.append(css)
8284
}
8385
}
84-
86+
rule.parent.after(parentAfterNodes)
8587
rule.remove()
8688
})
8789
}

test/__snapshots__/postcss.test.ts.snap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`postcss > @apply 1`] = `"div{--un-bg-opacity:1;background-color:rgba(248,113,113,var(--un-bg-opacity));}div:hover{--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}.dark div>:focus:hover{font-size:20px;}"`;
3+
exports[`postcss > @apply > basic 1`] = `"div{--un-bg-opacity:1;background-color:rgba(248,113,113,var(--un-bg-opacity));}.dark div>:focus:hover{font-size:20px;}div:hover{--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}"`;
4+
5+
exports[`postcss > @apply > media 1`] = `"div{}@media (min-width: 640px){div{--un-bg-opacity:1;background-color:rgba(248,113,113,var(--un-bg-opacity));}}@media (min-width: 768px){div{--un-bg-opacity:1;background-color:rgba(96,165,250,var(--un-bg-opacity));}}@media (min-width: 1024px){div{--un-bg-opacity:1;background-color:rgba(244,114,182,var(--un-bg-opacity));}}@media (min-width: 1280px){div{--un-bg-opacity:1;background-color:rgba(255,255,255,var(--un-bg-opacity));}}"`;
46

57
exports[`postcss > @screen 1`] = `
68
"@media (min-width: 768px) and (max-width: 1023.9px) {
7-
div{--un-bg-opacity:1;background-color:rgba(248,113,113,var(--un-bg-opacity));}div:hover{--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}.dark div>:focus:hover{font-size:20px;}
9+
div{--un-bg-opacity:1;background-color:rgba(248,113,113,var(--un-bg-opacity));}
10+
.dark div>:focus:hover{font-size:20px;}
11+
div:hover{--un-text-opacity:1;color:rgba(255,255,255,var(--un-text-opacity));}
812
div{color:#dc2626}
913
}"
1014
`;

test/postcss.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,17 @@ describe('postcss', () => {
115115
expect(css).toMatchSnapshot()
116116
})
117117

118-
test('@apply', async () => {
119-
const { css } = await pcssLite().process('div{@apply bg-red hover:text-white dark:hover:[&>:focus]:text-[20px];}', processOptions)
118+
describe('@apply', () => {
119+
test('basic', async () => {
120+
const { css } = await pcssLite().process('div{@apply bg-red hover:text-white dark:hover:[&>:focus]:text-[20px];}', processOptions)
120121

121-
expect(css).toMatchSnapshot()
122+
expect(css).toMatchSnapshot()
123+
})
124+
125+
test('media', async () => {
126+
const { css } = await pcssLite().process('div{@apply sm:bg-red lg:bg-pink xl:bg-white md:bg-blue}', processOptions)
127+
expect(css).toMatchSnapshot()
128+
})
122129
})
123130

124131
test('theme()', async () => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy