Skip to content

fix(generator): forward variant props via forwardProps in withProvider#3549

Merged
segunadebayo merged 2 commits into
mainfrom
fix/forward-props-with-provider
May 24, 2026
Merged

fix(generator): forward variant props via forwardProps in withProvider#3549
segunadebayo merged 2 commits into
mainfrom
fix/forward-props-with-provider

Conversation

@segunadebayo
Copy link
Copy Markdown
Member

@segunadebayo segunadebayo commented May 24, 2026

What's wrong

Fixes #3547.

forwardProps did nothing on withProvider from createStyleContext. The function pulls variant props out (with splitVariantProps) before it passes the rest to the wrapped component, so a variant prop you listed in forwardProps never reached the component. It just came through as undefined.

The fix

If a variant prop is listed in forwardProps, it still drives the slot styles and now also reaches the component.

const { withProvider } = createStyleContext(tabs)

function TabsRoot({ orientation, ...rest }) {
  // orientation is defined here now, instead of undefined
  return <div aria-orientation={orientation} {...rest} />
}

export const Tabs = withProvider(TabsRoot, 'root', { forwardProps: ['orientation'] })

The change is per framework because the prop models differ:

  • React and Preact: after splitting, re-attach the forwarded keys, guarded by key in variantProps. The guard matters. Without it, forwarding a prop that's already there throws on React 19's frozen props, and an unset variant would overwrite defaultProps with undefined.
  • Vue: same re-attach, but inside the existing res computed so it stays reactive.
  • Solid: forwarded through getters merged with mergeProps instead of a one-time copy, so reactivity is preserved.

withContext already worked (it never splits variant props), so it's unchanged.

Tests

Added a forwardProps test for each framework, plus a Solid test that changes the variant after render and checks the forwarded value updates. That one would fail if Solid used a plain copy instead of getters. All four suites pass, and the generator package tests pass.

Docs

  • style-props.mdx: documents forwardProps on the styled factory (it was missing from FactoryOptions), including the note that a forwarded prop no longer feeds styling.
  • jsx-style-context.mdx: new "Forwarding props" section covering withProvider and withContext.

Left out on purpose

  • withRootProvider has no forwardProps option and no underlying factory, so supporting it is a new feature rather than a bug fix.
  • Two existing factory behaviors (forwardProps on a recipe variant drops its styling, and nested styled components can override an explicit forwardProps) are documented but not changed, since touching them would shift CSS and forwarding output.

withProvider split variant props out before passing them to the wrapped
component, so props listed in `forwardProps` were silently dropped. Now a
variant prop named in `forwardProps` still drives the slot styles and is
forwarded to the component, across the React, Preact, Vue, and Solid
outputs. The Solid implementation forwards via getters to preserve
reactivity.

Also documents `forwardProps` on the styled factory and createStyleContext.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

🦋 Changeset detected

Latest commit: edfbeed

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

This PR includes changesets to release 24 packages
Name Type
@pandacss/generator Patch
@pandacss/node Patch
@pandacss/parser Patch
@pandacss/reporter 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/extractor 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/shared Patch
@pandacss/token-dictionary Patch
@pandacss/types 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

@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

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

Project Deployment Actions Updated (UTC)
panda-docs Ready Ready Preview May 24, 2026 12:24pm
panda-playground Ready Ready Preview May 24, 2026 12:24pm
panda-studio Ready Ready Preview May 24, 2026 12:24pm

Request Review

No co-author trailer on commits, and write commits, PRs, and comments in
plain human language (no em-dashes, no AI filler).
@segunadebayo segunadebayo merged commit c0511b8 into main May 24, 2026
7 checks passed
@segunadebayo segunadebayo deleted the fix/forward-props-with-provider branch May 24, 2026 19:40
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.

Should forwardProps work at all on withProvider from createStyleContext

1 participant