Skip to content

fix(extractor): extract React automatic JSX runtime calls#3515

Draft
KimHyeongRae0 wants to merge 1 commit intochakra-ui:mainfrom
KimHyeongRae0:fix/extract-react-jsx-runtime-calls
Draft

fix(extractor): extract React automatic JSX runtime calls#3515
KimHyeongRae0 wants to merge 1 commit intochakra-ui:mainfrom
KimHyeongRae0:fix/extract-react-jsx-runtime-calls

Conversation

@KimHyeongRae0
Copy link
Copy Markdown

@KimHyeongRae0 KimHyeongRae0 commented Apr 20, 2026

Closes #3509

📝 Description

React's automatic JSX runtime lowers <Box css={{ color: 'red' }} /> to jsx(Box, { css: { color: 'red' } }) (or jsxs/jsxDEV). The extractor did not recognize those calls, so Panda would silently produce no CSS when scanning already-compiled files — e.g. the published dist bundle of a component library that a downstream app wants to tree-shake.

This PR teaches the extractor to handle the three React automatic-runtime helpers (jsx, jsxs, jsxDEV) as synthetic component instances and route their second-argument object literal through the same component-matching / prop-matching pipeline used for real JSX.

⛳️ Current behavior

  • Source form <Box css={{ bg: 'red.200' }} /> → extracted ✅
  • Pre-defined variable <Box css={styles} /> → extracted in both source and compiled forms ✅
  • Compiled form jsx(Box, { css: { bg: 'red.200' } })not extracted

🚀 New behavior

  • jsx(Component, { css: { ... } }), jsxs(Component, { ... }), jsxDEV(Component, { ... }) are all routed through the existing components.matchTag / components.matchProp / maybeBoxNode pipeline.
  • Handles PropertyAssignment and ShorthandPropertyAssignment entries in the props object literal.
  • No change for any non-runtime call; the functions branch and tagged-template branch are untouched.
  • No change to existing JSX element handling.
  • The atomic-rule snapshots (CSS-output-sacred per CLAUDE.md) are unchanged.

Intentionally out of scope

  • SpreadAssignment inside the props object (e.g. jsx(Box, { ...rest, css: {...} })) — left for a follow-up to keep this PR narrow. Current behavior (nothing extracted) is preserved.
  • Non-React JSX runtime factories — this PR hardcodes the three React names per the react/jsx-runtime spec. A config-level opt-in for custom factory names can be added later if there's demand.

💣 Is this a breaking change (Yes/No)

No. The change is purely additive: CallExpressions that were previously invisible to the extractor now flow through the existing component pipeline. Files that didn't contain jsx()/jsxs()/jsxDEV() calls are unaffected.

📝 Additional Information

Tests

  • Added a regression test in packages/parser/__tests__/css-prop.test.ts that mirrors the StackBlitz repro from css prop inline object literals not extracted from compiled (dist) files #3509 (inline css={{ bg: 'red.200' }} on a user component in compiled-jsx() form). Without the fix, result.css === ""; with the fix, it emits the expected bg_red.200 rule.
  • Local test runs:
    • pnpm test packages/extractor — 153 passed / 1 skipped (unchanged)
    • pnpm test packages/parser — 203 passed (new test included)
    • pnpm test packages/core — 234 passed, no snapshot drift

Changeset

@pandacss/extractor, @pandacss/parser → patch.

See the pre-PR comment on #3509 for context.

Recognize `jsx`, `jsxs`, and `jsxDEV` call expressions produced by React's
automatic JSX runtime (react/jsx-runtime, react/jsx-dev-runtime) as synthetic
component instances. When the second argument is an object literal, its
`PropertyAssignment` and `ShorthandPropertyAssignment` entries are walked
through the same `components.matchTag` / `components.matchProp` /
`maybeBoxNode` pipeline used for real JSX attributes.

This lets Panda extract styles from already-compiled code — e.g. a component
library's published `dist` bundle — where `<Box css={{ color: 'red' }} />`
has been lowered to `jsx(Box, { css: { color: 'red' } })`.

Closes chakra-ui#3509
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
panda-docs Ready Ready Preview Apr 20, 2026 2:33pm

Request Review

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

@KimHyeongRae0 is attempting to deploy a commit to the Chakra UI Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: fff893d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@pandacss/extractor Patch
@pandacss/parser Patch
@pandacss/types Patch
@pandacss/node Patch
@pandacss/astro-plugin-studio Patch
@pandacss/dev Patch
@pandacss/mcp Patch
@pandacss/postcss Patch
@pandacss/studio Patch
@pandacss/config Patch
@pandacss/core Patch
@pandacss/generator Patch
@pandacss/is-valid-prop Patch
@pandacss/logger Patch
@pandacss/plugin-lightningcss Patch
@pandacss/plugin-svelte Patch
@pandacss/plugin-vue Patch
@pandacss/preset-atlaskit Patch
@pandacss/preset-base Patch
@pandacss/preset-open-props Patch
@pandacss/preset-panda Patch
@pandacss/reporter Patch
@pandacss/shared Patch
@pandacss/token-dictionary Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

css prop inline object literals not extracted from compiled (dist) files

1 participant