From 2e53a29d8e7a68549b2b12a8fe63297cf3ce0c28 Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Thu, 20 Apr 2017 12:37:34 +0200 Subject: [PATCH 1/2] 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. --- src/isomorphic/children/traverseAllChildren.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/isomorphic/children/traverseAllChildren.js b/src/isomorphic/children/traverseAllChildren.js index a68d1816d68..454e404628e 100644 --- a/src/isomorphic/children/traverseAllChildren.js +++ b/src/isomorphic/children/traverseAllChildren.js @@ -45,7 +45,7 @@ var didWarnAboutMaps = false; function getComponentKey(component, index) { // Do some typechecking here since we call this blindly. We want to ensure // that we don't block potential future ES APIs. - if (component && typeof component === 'object' && component.key != null) { + if (typeof component === 'object' && component !== null && component.key != null) { // Explicit key return KeyEscapeUtils.escape(component.key); } From bc2479fe847fc3e4a59a44c65323ae553a6a215b Mon Sep 17 00:00:00 2001 From: Benedikt Meurer Date: Thu, 20 Apr 2017 19:06:39 +0200 Subject: [PATCH 2/2] Run yarn prettier. --- src/isomorphic/children/traverseAllChildren.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/isomorphic/children/traverseAllChildren.js b/src/isomorphic/children/traverseAllChildren.js index 454e404628e..7d2634b473c 100644 --- a/src/isomorphic/children/traverseAllChildren.js +++ b/src/isomorphic/children/traverseAllChildren.js @@ -45,7 +45,9 @@ var didWarnAboutMaps = false; function getComponentKey(component, index) { // Do some typechecking here since we call this blindly. We want to ensure // that we don't block potential future ES APIs. - if (typeof component === 'object' && component !== null && component.key != null) { + if ( + typeof component === 'object' && component !== null && component.key != null + ) { // Explicit key return KeyEscapeUtils.escape(component.key); }