Skip to content

Commit 0e587c1

Browse files
bmeurerbvaughn
authored andcommitted
Improve component type check in getComponentKey. (#9464)
* 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.
1 parent a9d0deb commit 0e587c1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/isomorphic/children/traverseAllChildren.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ var didWarnAboutMaps = false;
4848
function getComponentKey(component, index) {
4949
// Do some typechecking here since we call this blindly. We want to ensure
5050
// that we don't block potential future ES APIs.
51-
if (component && typeof component === 'object' && component.key != null) {
51+
if (
52+
typeof component === 'object' && component !== null && component.key != null
53+
) {
5254
// Explicit key
5355
return KeyEscapeUtils.escape(component.key);
5456
}

0 commit comments

Comments
 (0)