RawLabel: Fix crash when text is empty string.#4801
Conversation
ab67152 to
0c70b5f
Compare
0c70b5f to
421f79e
Compare
421f79e to
a760a73
Compare
chrisbobbe
left a comment
There was a problem hiding this comment.
Thanks for catching this!! One tiny correctness hole that I think I've found, below; possibly not worth addressing, but also wouldn't be too hard to address if you chose to.
| const { text, children, style, ...restProps } = this.props; | ||
|
|
||
| invariant(!!text !== !!children, 'pass either `text` or `children`'); | ||
| invariant((text != null) !== !!children, 'pass either `text` or `children`'); |
There was a problem hiding this comment.
It occurs to me that children can be a number or a string; it's typed ?Node (link) and I think the type Flow uses for Node includes strings and numbers (doc).
It'd be super weird, but I guess one could pass "foo" for text and 0 for children, and circumvent this check, ending up with "foo0" on the screen?
I'm trying to think whether that case is totally wacky and you'd really have to be trying to find it in order for it to be active. Or if you could stumble on it innocently.
I think it's not totally impossible to stumble on it innocently: there's this gotcha in this conditional rendering doc from React:
Note that returning a falsy expression will still cause the element after
&&to be skipped but will return the falsy expression. In the example below,<div>0</div>will be returned by the render method.
If you're passing children and you've accidentally stumbled on that gotcha there, and you're also passing a string for text, there could be a case like foo0.
There was a problem hiding this comment.
Yeah, seems cleanest to use the same != null for children as well.
Thanks @WesleyAC for catching this!
a760a73 to
d79819c
Compare
|
Revision pushed :) |
This was causing a crash when trying to autocomplete a user group with a blank name. The empty string was passed into RawLabel, which caused this invariant to incorrectly trigger. This appears to have been introduced in 199a190. Instead of using `!!` to check for undefined, we can do `!= null`, which will trigger for undefined and null, but not an empty string.
d79819c to
de91779
Compare
|
Looks good, thanks -- merged! |
This was causing a crash when trying to autocomplete a user group with a
blank name. The empty string was passed into RawLabel, which caused this
invariant to incorrectly trigger.
Instead of using
!!to check for undefined, we can do!= null, whichwill trigger for undefined and null, but not an empty string.
If you want to trigger this on CZO, just type
@testinto the composebox :)