fix(generator): forward variant props via forwardProps in withProvider#3549
Merged
Conversation
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 detectedLatest commit: edfbeed 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
No co-author trailer on commits, and write commits, PRs, and comments in plain human language (no em-dashes, no AI filler).
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.
What's wrong
Fixes #3547.
forwardPropsdid nothing onwithProviderfromcreateStyleContext. The function pulls variant props out (withsplitVariantProps) before it passes the rest to the wrapped component, so a variant prop you listed inforwardPropsnever reached the component. It just came through asundefined.The fix
If a variant prop is listed in
forwardProps, it still drives the slot styles and now also reaches the component.The change is per framework because the prop models differ:
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 overwritedefaultPropswithundefined.rescomputed so it stays reactive.mergePropsinstead of a one-time copy, so reactivity is preserved.withContextalready worked (it never splits variant props), so it's unchanged.Tests
Added a
forwardPropstest 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: documentsforwardPropson the styled factory (it was missing fromFactoryOptions), including the note that a forwarded prop no longer feeds styling.jsx-style-context.mdx: new "Forwarding props" section coveringwithProviderandwithContext.Left out on purpose
withRootProviderhas noforwardPropsoption and no underlying factory, so supporting it is a new feature rather than a bug fix.styledcomponents can override an explicitforwardProps) are documented but not changed, since touching them would shift CSS and forwarding output.