Skip to content

Improve component type check in getComponentKey. - #9464

Merged
bvaughn merged 2 commits into
react:masterfrom
bmeurer:getComponentKey_TypeCheck
Apr 25, 2017
Merged

bvaughn merged 2 commits into
react:masterfrom
bmeurer:getComponentKey_TypeCheck

Conversation

@bmeurer

@bmeurer bmeurer commented Apr 20, 2017

Copy link
Copy Markdown
Contributor

The sequence

component && typeof component === 'object'

checks whether component is any JavaScript object except document.all.
Since document.all cannot occur here, this can be replaced with the
usual

typeof component === 'object' && component !== null

sequence, which yields true for all JavaScript objects and is well
optimized by all JavaScript engines.

The sequence
```
component && typeof component === 'object'
```
checks whether component is any JavaScript object except document.all.
Since document.all cannot occur here, this can be replaced with the
usual
```
typeof component === 'object' && component !== null
```
sequence, which yields true for all JavaScript objects and is well
optimized by all JavaScript engines.
@gaearon

gaearon commented Apr 20, 2017

Copy link
Copy Markdown
Collaborator

Looks good to me, thanks. Let’s wait for CI.

@bmeurer

bmeurer commented Apr 20, 2017

Copy link
Copy Markdown
Contributor Author

That being said: it obviously filters out callable objects still.

@bvaughn

bvaughn commented Apr 20, 2017

Copy link
Copy Markdown
Contributor

Looks like you need to run yarn prettier to format the code. Since the line's longer now, Prettier wants to split it:

if (
  typeof component === "object" &&
  component !== null &&
  component.key != null
) {

@bmeurer

bmeurer commented Apr 20, 2017 •

Copy link
Copy Markdown
Contributor Author

Done. Although it didn't split it into three lines.

@gaearon

gaearon commented Apr 20, 2017

Copy link
Copy Markdown
Collaborator

Likely because we haven’t updated to the last version yet (we will soon).

@bmeurer

bmeurer commented Apr 25, 2017

Copy link
Copy Markdown
Contributor Author

Anything else missing?

@bvaughn

bvaughn commented Apr 25, 2017

Copy link
Copy Markdown
Contributor

Oh, my bad. My local prettier did but I may have been using a diff version. :)

No, looks good. Thanks for following up!

@bvaughn
bvaughn merged commit 0e587c1 into react:master Apr 25, 2017
@bmeurer

bmeurer commented Apr 25, 2017

Copy link
Copy Markdown
Contributor Author

Thanks!

@sophiebits

Copy link
Copy Markdown
Collaborator

Thanks @bmeurer!

koba04 added a commit to koba04/react that referenced this pull request Apr 26, 2017
koba04 added a commit to koba04/react that referenced this pull request May 8, 2017
koba04 added a commit to koba04/react that referenced this pull request Jun 12, 2017
koba04 added a commit to koba04/react that referenced this pull request Jun 29, 2017
mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
* Improve component type check in getComponentKey.

The sequence
```
component && typeof component === 'object'
```
checks whether component is any JavaScript object except document.all.
Since document.all cannot occur here, this can be replaced with the
usual
```
typeof component === 'object' && component !== null
```
sequence, which yields true for all JavaScript objects and is well
optimized by all JavaScript engines.

* Run yarn prettier.
hanzo-dev pushed a commit to hanzoai/react that referenced this pull request Sep 9, 2026
* Improve component type check in getComponentKey.

The sequence
```
component && typeof component === 'object'
```
checks whether component is any JavaScript object except document.all.
Since document.all cannot occur here, this can be replaced with the
usual
```
typeof component === 'object' && component !== null
```
sequence, which yields true for all JavaScript objects and is well
optimized by all JavaScript engines.

* Run yarn prettier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants