Skip to content

Commit

Permalink
fix: eager extraction on URL values with valid property name (#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
astahmer authored Dec 3, 2023
1 parent 052283c commit 788aaba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .changeset/healthy-pants-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@pandacss/core': patch
---

Fix an edge-case when Panda eagerly extracted and tried to generate the CSS for a JSX property that contains an URL.

```tsx
const App = () => {
// here the content property is a valid CSS property, so Panda will try to generate the CSS for it
// but since it's an URL, it would produce invalid CSS
// we now check if the property value is an URL and skip it if needed
return <CopyButton content="https://www.buymeacoffee.com/grizzlycodes" />
}
```
7 changes: 7 additions & 0 deletions packages/core/src/atomic-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface ProcessOptions {
styles: Dict
}

const urlRegex = /^https?:\/\//

export class AtomicRule {
root: Root
layer: string
Expand Down Expand Up @@ -61,6 +63,11 @@ export class AtomicRule {
// if value doesn't exist
if (value == null) return

// we don't want to extract and generate invalid CSS for urls
if (urlRegex.test(value)) {
return
}

const important = isImportant(value)

// conditions.shift was done to support condition groups
Expand Down
24 changes: 24 additions & 0 deletions packages/parser/__tests__/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,30 @@ describe('extract to css output pipeline', () => {
}"
`)
})

test('urls as value', () => {
const code = `
const App = () => {
return <CopyButton content="https://www.buymeacoffee.com/grizzlycodes" />
}
`
const result = run(code, { strictTokens: true })
expect(result.json).toMatchInlineSnapshot(`
[
{
"data": [
{
"content": "https://www.buymeacoffee.com/grizzlycodes",
},
],
"name": "CopyButton",
"type": "jsx",
},
]
`)

expect(result.css).toMatchInlineSnapshot('""')
})
})

describe('preset patterns', () => {
Expand Down

3 comments on commit 788aaba

@vercel
Copy link

@vercel vercel bot commented on 788aaba Dec 3, 2023

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-studio-git-main-chakra-ui.vercel.app
panda-app.vercel.app
panda-studio-chakra-ui.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 788aaba Dec 3, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 788aaba Dec 3, 2023

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-chakra-ui.vercel.app
panda-docs.vercel.app
panda-css.com

Please sign in to comment.