From 4b734f7a025c828be8c5d85f7c8d88679ae8f952 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 12 Aug 2016 18:34:46 +0100 Subject: [PATCH] Improve DEV performance in Chrome (#7483) * Ensure this._domID is always a number * Ensure this._rootNodeID is always a number --- src/renderers/dom/client/ReactDOMComponentTree.js | 2 +- src/renderers/dom/shared/ReactDOMComponent.js | 8 ++++---- src/renderers/dom/shared/ReactDOMEmptyComponent.js | 2 +- src/renderers/dom/shared/ReactDOMTextComponent.js | 2 +- .../dom/shared/__tests__/ReactDOMComponent-test.js | 4 ++-- src/renderers/native/ReactNativeBaseComponent.js | 2 +- src/renderers/native/ReactNativeTextComponent.js | 4 ++-- src/renderers/native/createReactNativeComponentClass.js | 2 +- .../shared/stack/reconciler/ReactCompositeComponent.js | 4 ++-- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/renderers/dom/client/ReactDOMComponentTree.js b/src/renderers/dom/client/ReactDOMComponentTree.js index 4d9b8315c853c..8ff3260e8508e 100644 --- a/src/renderers/dom/client/ReactDOMComponentTree.js +++ b/src/renderers/dom/client/ReactDOMComponentTree.js @@ -81,7 +81,7 @@ function precacheChildNodes(inst, node) { } var childInst = children[name]; var childID = getRenderedHostOrTextFromComponent(childInst)._domID; - if (childID == null) { + if (childID === 0) { // We're currently unmounting this child in ReactMultiChild; skip it. continue; } diff --git a/src/renderers/dom/shared/ReactDOMComponent.js b/src/renderers/dom/shared/ReactDOMComponent.js index c961d083ed80c..e97ea68c85d4c 100644 --- a/src/renderers/dom/shared/ReactDOMComponent.js +++ b/src/renderers/dom/shared/ReactDOMComponent.js @@ -488,8 +488,8 @@ function ReactDOMComponent(element) { this._previousStyleCopy = null; this._hostNode = null; this._hostParent = null; - this._rootNodeID = null; - this._domID = null; + this._rootNodeID = 0; + this._domID = 0; this._hostContainerInfo = null; this._wrapperState = null; this._topLevelWrapper = null; @@ -1190,8 +1190,8 @@ ReactDOMComponent.Mixin = { this.unmountChildren(safely); ReactDOMComponentTree.uncacheNode(this); EventPluginHub.deleteAllListeners(this); - this._rootNodeID = null; - this._domID = null; + this._rootNodeID = 0; + this._domID = 0; this._wrapperState = null; if (__DEV__) { diff --git a/src/renderers/dom/shared/ReactDOMEmptyComponent.js b/src/renderers/dom/shared/ReactDOMEmptyComponent.js index d77ea340582bd..0a7b8c6b2f01f 100644 --- a/src/renderers/dom/shared/ReactDOMEmptyComponent.js +++ b/src/renderers/dom/shared/ReactDOMEmptyComponent.js @@ -22,7 +22,7 @@ var ReactDOMEmptyComponent = function(instantiate) { this._hostNode = null; this._hostParent = null; this._hostContainerInfo = null; - this._domID = null; + this._domID = 0; }; Object.assign(ReactDOMEmptyComponent.prototype, { mountComponent: function( diff --git a/src/renderers/dom/shared/ReactDOMTextComponent.js b/src/renderers/dom/shared/ReactDOMTextComponent.js index fa589e7886204..24b0027d2600e 100644 --- a/src/renderers/dom/shared/ReactDOMTextComponent.js +++ b/src/renderers/dom/shared/ReactDOMTextComponent.js @@ -43,7 +43,7 @@ var ReactDOMTextComponent = function(text) { this._hostParent = null; // Properties - this._domID = null; + this._domID = 0; this._mountIndex = 0; this._closingComment = null; this._commentNodes = null; diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index be0b0269ab3d1..7688623e435b3 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -634,7 +634,7 @@ describe('ReactDOMComponent', function() { var NodeStub = function(initialProps) { this._currentElement = {props: initialProps}; - this._rootNodeID = 'test'; + this._rootNodeID = 1; }; Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin); @@ -690,7 +690,7 @@ describe('ReactDOMComponent', function() { var NodeStub = function(initialProps) { this._currentElement = {props: initialProps}; - this._rootNodeID = 'test'; + this._rootNodeID = 1; }; Object.assign(NodeStub.prototype, ReactDOMComponent.Mixin); diff --git a/src/renderers/native/ReactNativeBaseComponent.js b/src/renderers/native/ReactNativeBaseComponent.js index 0a0c8435b799d..5d131739fc986 100644 --- a/src/renderers/native/ReactNativeBaseComponent.js +++ b/src/renderers/native/ReactNativeBaseComponent.js @@ -59,7 +59,7 @@ ReactNativeBaseComponent.Mixin = { ReactNativeComponentTree.uncacheNode(this); deleteAllListeners(this); this.unmountChildren(); - this._rootNodeID = null; + this._rootNodeID = 0; }, /** diff --git a/src/renderers/native/ReactNativeTextComponent.js b/src/renderers/native/ReactNativeTextComponent.js index 67a9b865fa421..8e815f9efb20a 100644 --- a/src/renderers/native/ReactNativeTextComponent.js +++ b/src/renderers/native/ReactNativeTextComponent.js @@ -22,7 +22,7 @@ var ReactNativeTextComponent = function(text) { this._currentElement = text; this._stringText = '' + text; this._hostParent = null; - this._rootNodeID = null; + this._rootNodeID = 0; }; Object.assign(ReactNativeTextComponent.prototype, { @@ -73,7 +73,7 @@ Object.assign(ReactNativeTextComponent.prototype, { ReactNativeComponentTree.uncacheNode(this); this._currentElement = null; this._stringText = null; - this._rootNodeID = null; + this._rootNodeID = 0; }, }); diff --git a/src/renderers/native/createReactNativeComponentClass.js b/src/renderers/native/createReactNativeComponentClass.js index adb0740bcf88e..351a2b5797858 100644 --- a/src/renderers/native/createReactNativeComponentClass.js +++ b/src/renderers/native/createReactNativeComponentClass.js @@ -33,7 +33,7 @@ var createReactNativeComponentClass = function( this._topLevelWrapper = null; this._hostParent = null; this._hostContainerInfo = null; - this._rootNodeID = null; + this._rootNodeID = 0; this._renderedChildren = null; }; Constructor.displayName = viewConfig.uiViewClassName; diff --git a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js index a4f7c1c203457..d9de0a913debe 100644 --- a/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js +++ b/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js @@ -153,7 +153,7 @@ var ReactCompositeComponentMixin = { */ construct: function(element) { this._currentElement = element; - this._rootNodeID = null; + this._rootNodeID = 0; this._compositeType = null; this._instance = null; this._hostParent = null; @@ -612,7 +612,7 @@ var ReactCompositeComponentMixin = { // These fields do not really need to be reset since this object is no // longer accessible. this._context = null; - this._rootNodeID = null; + this._rootNodeID = 0; this._topLevelWrapper = null; // Delete the reference from the instance to this internal representation