@samitouri / QOS-React-2 / commits / 0e587c1a8e

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.

Benedikt Meurer committed Apr 25, 2017 at 18:39 UTC 0e587c1a8e49d65db4fc75bacf00733a2221c820
1 file changed +3 -1
src/isomorphic/children/traverseAllChildren.js
+3 -1
@@ -48,7 +48,9 @@ var didWarnAboutMaps = false;
48 function getComponentKey(component, index) {
49 // Do some typechecking here since we call this blindly. We want to ensure
50 // 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 + ) {
54 // Explicit key
55 return KeyEscapeUtils.escape(component.key);
56 }