Skip to content

Commit a67f920

Browse files
authored
fix: theme skipping not skipping a theme if its name also starts with another theme name (#3251)
1 parent 5bf8f00 commit a67f920

3 files changed

Lines changed: 105 additions & 1 deletion

File tree

.changeset/warm-turtles-behave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@pandacss/generator': patch
3+
---
4+
5+
This change fixes a issue where if two themes had shared a similar start name, both would be outputted in the token
6+
generation process

packages/generator/__tests__/generate-token.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,104 @@ describe('generator', () => {
10531053
`)
10541054
})
10551055

1056+
test('themes - staticCss with multiple themes ', () => {
1057+
const css = tokenCss({
1058+
eject: true,
1059+
conditions: {
1060+
osDark: '@media (prefers-color-scheme: dark)',
1061+
},
1062+
theme: {
1063+
tokens: {
1064+
colors: {
1065+
text: { value: 'blue' },
1066+
},
1067+
},
1068+
semanticTokens: {
1069+
colors: {
1070+
body: {
1071+
value: {
1072+
base: '{colors.blue.600}',
1073+
_osDark: '{colors.blue.400}',
1074+
},
1075+
},
1076+
},
1077+
},
1078+
},
1079+
// alternative theme variants
1080+
themes: {
1081+
primary: {
1082+
tokens: {
1083+
colors: {
1084+
text: { value: 'red' },
1085+
},
1086+
},
1087+
semanticTokens: {
1088+
colors: {
1089+
muted: { value: '{colors.red.200}' },
1090+
body: {
1091+
value: {
1092+
base: '{colors.red.600}',
1093+
_osDark: '{colors.red.400}',
1094+
},
1095+
},
1096+
},
1097+
},
1098+
},
1099+
'primary-legacy': {
1100+
tokens: {
1101+
colors: {
1102+
text: { value: 'blue' },
1103+
},
1104+
},
1105+
semanticTokens: {
1106+
colors: {
1107+
muted: { value: '{colors.blue.200}' },
1108+
body: {
1109+
value: {
1110+
base: '{colors.blue.600}',
1111+
_osDark: '{colors.blue.400}',
1112+
},
1113+
},
1114+
},
1115+
},
1116+
},
1117+
},
1118+
staticCss: {
1119+
// only generate the red in addition to the main one
1120+
themes: ['primary'],
1121+
// use ['*'] to generate all themes
1122+
},
1123+
outdir: '',
1124+
})
1125+
1126+
expect(css).toMatchInlineSnapshot(`
1127+
"@layer tokens {
1128+
:where(html) {
1129+
--colors-text: blue;
1130+
--colors-body: var(--colors-blue-600);
1131+
}
1132+
1133+
[data-panda-theme=primary] {
1134+
--colors-text: red;
1135+
--colors-muted: var(--colors-red-200);
1136+
--colors-body: var(--colors-red-600)
1137+
}
1138+
1139+
@media (prefers-color-scheme: dark) {
1140+
:where(html) {
1141+
--colors-body: var(--colors-blue-400)
1142+
}
1143+
}
1144+
1145+
@media (prefers-color-scheme: dark) {
1146+
[data-panda-theme=primary] {
1147+
--colors-body: var(--colors-red-400)
1148+
}
1149+
}
1150+
}"
1151+
`)
1152+
})
1153+
10561154
test('themes - staticCss with *', () => {
10571155
const css = tokenCss({
10581156
eject: true,

packages/generator/src/artifacts/css/token-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function generateTokenCss(ctx: Context, sheet: Stylesheet) {
2424
const themePrefix = ctx.conditions.getThemeName('')
2525

2626
for (const [key, values] of tokens.view.vars.entries()) {
27-
const isThemeSkipped = key.startsWith(themePrefix) && !themeConds.some((condName) => key.startsWith(condName))
27+
const isThemeSkipped = key.startsWith(themePrefix) && !themeConds.some((condName) => key === condName || key.startsWith(condName + ':'))
2828
if (isThemeSkipped) {
2929
continue
3030
}

0 commit comments

Comments
 (0)