Skip to content

Commit

Permalink
fix: conditions accessing (#2268)
Browse files Browse the repository at this point in the history
  • Loading branch information
astahmer authored Feb 26, 2024
1 parent 6a23fbb commit 5a205e7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/red-comics-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@pandacss/generator': patch
'@pandacss/core': patch
---

Fix conditions accessing `Cannot read properties of undefined (reading 'raw')`
4 changes: 2 additions & 2 deletions packages/core/src/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ export class Conditions {
return Object.keys(this.values).length === 0
}

get = (key: string) => {
get = (key: string): undefined | string | string[] => {
const details = this.values[key]
return details.raw
return details?.raw
}

getRaw = (condNameOrQuery: ConditionQuery): ConditionDetails | undefined => {
Expand Down
6 changes: 5 additions & 1 deletion packages/generator/src/artifacts/css/token-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ export function generateTokenCss(ctx: Context, sheet: Stylesheet) {
.filter(Boolean)
.map((condition) => {
const lastSegment = Array.isArray(condition) ? condition.at(-1)! : condition
if (!lastSegment) return
const parent = extractParentSelectors(lastSegment)
// ASSUMPTION: the nature of parent selectors with tokens is that they're merged
// [data-color-mode=dark][data-theme=pastel]
// If we really want it nested, we remove the `&`
return parent ? `&${parent}` : lastSegment
})
.filter(Boolean)

if (!mapped.length) return

const rule = getDeepestRule(root, mapped)
const rule = getDeepestRule(root, mapped as string[])
if (!rule) continue

getDeepestNode(rule)?.append(css)
Expand Down
2 changes: 1 addition & 1 deletion packages/generator/src/artifacts/js/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function generateConditions(ctx: Context) {
key === 'base'
? `/** The base (=no conditions) styles to apply */\n`
: ctx.conditions.get(key)
? `/** \`${([] as string[]).concat(ctx.conditions.get(key)).join(' ')}\` */\n`
? `/** \`${([] as string[]).concat(ctx.conditions.get(key) ?? '').join(' ')}\` */\n`
: ''
}\t${JSON.stringify(key)}: string`,
)
Expand Down

0 comments on commit 5a205e7

Please sign in to comment.