-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HStack, VStack: Stop passing invalid props #59416
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -22,7 +22,7 @@ import type { FlexProps } from '../types'; | |||
|
|||
function useDeprecatedProps( | |||
props: WordPressComponentProps< FlexProps, 'div' > | |||
): WordPressComponentProps< FlexProps, 'div' > { | |||
): Omit< typeof props, 'isReversed' > { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return type was wrong because it wasn't omitting the deprecated isReversed
prop, which is specifically being omitted in this hook. It wasn't causing a TS error per se, but it was making it look like useFlex
could return another invalid prop (isReversed
) in addition to isColumn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the quick fix 🙏
I just want to ask you one thing: After this PR is merged, it's safe to use the implementation below, right?
<HStack as={ motion.div }></HStack>
<VStack as={ motion.div }></VStack>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice and straightforward, thanks! 🚀
@t-hamano That's correct 👍 |
Fixes a bug surfaced in #59193
What?
Stops the HStack and VStack components from passing through invalid props when a component is passed to the
as
prop.Why?
The
useHStack
/useVStack
hooks internally used theuseFlex
hook to generate props, which included theisColumn
prop. This prop is actually used in theFlex
component logic and not passed through to the underlying element, but was neither used nor omitted in the HStack/VStack components and thus passed through.This is fine if an intrinsic element (such as "span") is used for the
as
prop, since the underlyingView
component (i.e. an Emotion-styled component) will correctly ignore non-intrinsic props. It can become a problem when a non-Emotion custom component is used for theas
prop, because React will throw an error about the invalid prop.How?
Omit the
isColumn
prop from the return props of theuseHStack
hook, which will also remove it from theuseVStack
hook.Testing Instructions