fix: default variant not being applied when setting variant property name#152
Open
wwdrew wants to merge 4 commits intoShopify:masterfrom
Open
fix: default variant not being applied when setting variant property name#152wwdrew wants to merge 4 commits intoShopify:masterfrom
wwdrew wants to merge 4 commits intoShopify:masterfrom
Conversation
Author
|
I've managed to get this working now, but one of the types isn't playing nicely and I'm not sure how to fix it. I hope this solution makes sense, I tried to make it as simple as possible. |
Author
|
I think I've cracked the types now, if someone can take a look at this PR that'd be great. |
fortmarek
reviewed
Jan 19, 2023
Contributor
fortmarek
left a comment
There was a problem hiding this comment.
Thanks for all the tests!
The changes look good, can you also add an entry into CHANGELOG? And sorry for the longer response here 🙇
| buildStyle, | ||
| properties, | ||
| propertiesMap, | ||
| variantProp: variantProp ? variantProp.property : 'variant', |
Contributor
There was a problem hiding this comment.
The default should be coming from here, so I don't think defaulting here to variant, too, is necessary.
Suggested change
| variantProp: variantProp ? variantProp.property : 'variant', | |
| variantProp: variantProp ? variantProp.property : undefined, |
Or possibly even variantProp: variantProp?.property, if that works.
|
Is this getting merged anytime soon? |
334b3da to
f86990a
Compare
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.
The recent PR (#148) that fixed the problem where defaults weren't being applied only works when the variant prop is the default value (
variant).If you're creating a component and using
createVariantto change the name of the variant prop, using thepropertyvalue, the defaults are no longer applied.I've taken a look at the code and from what I can see, on this line:
restyle/src/hooks/useRestyle.ts
Line 17 in e4a51db
It's hardcoded to check for
variant, but when changing this usingpropertyit's no longer this value, so it falls through.I've had a go at trying to fix this issue but I've not been able to come up with a solution yet. I've added some more exhaustive test cases to make sure all possibilities are being covered, but if someone could point me in the right direction to how to fix this issue I'd be happy to finish up the PR.
Hope you don't mind me submitting a WIP PR!