fix(extractor): extract React automatic JSX runtime calls#3515
Draft
KimHyeongRae0 wants to merge 1 commit intochakra-ui:mainfrom
Draft
fix(extractor): extract React automatic JSX runtime calls#3515KimHyeongRae0 wants to merge 1 commit intochakra-ui:mainfrom
KimHyeongRae0 wants to merge 1 commit intochakra-ui:mainfrom
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@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 detectedLatest commit: fff893d The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3509
📝 Description
React's automatic JSX runtime lowers
<Box css={{ color: 'red' }} />tojsx(Box, { css: { color: 'red' } })(orjsxs/jsxDEV). The extractor did not recognize those calls, so Panda would silently produce no CSS when scanning already-compiled files — e.g. the publisheddistbundle 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
<Box css={{ bg: 'red.200' }} />→ extracted ✅<Box css={styles} />→ extracted in both source and compiled forms ✅jsx(Box, { css: { bg: 'red.200' } })→ not extracted ❌🚀 New behavior
jsx(Component, { css: { ... } }),jsxs(Component, { ... }),jsxDEV(Component, { ... })are all routed through the existingcomponents.matchTag/components.matchProp/maybeBoxNodepipeline.PropertyAssignmentandShorthandPropertyAssignmententries in the props object literal.functionsbranch and tagged-template branch are untouched.atomic-rulesnapshots (CSS-output-sacred perCLAUDE.md) are unchanged.Intentionally out of scope
SpreadAssignmentinside 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.react/jsx-runtimespec. 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
packages/parser/__tests__/css-prop.test.tsthat mirrors the StackBlitz repro fromcssprop inline object literals not extracted from compiled (dist) files #3509 (inlinecss={{ bg: 'red.200' }}on a user component in compiled-jsx()form). Without the fix,result.css === ""; with the fix, it emits the expectedbg_red.200rule.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 driftChangeset
@pandacss/extractor,@pandacss/parser→ patch.See the pre-PR comment on #3509 for context.