diff --git a/src/renderers/shared/stack/reconciler/instantiateReactComponent.js b/src/renderers/shared/stack/reconciler/instantiateReactComponent.js index 6a8ed0a54ffb1..202768d8bba18 100644 --- a/src/renderers/shared/stack/reconciler/instantiateReactComponent.js +++ b/src/renderers/shared/stack/reconciler/instantiateReactComponent.js @@ -15,6 +15,7 @@ var ReactCompositeComponent = require('ReactCompositeComponent'); var ReactEmptyComponent = require('ReactEmptyComponent'); var ReactHostComponent = require('ReactHostComponent'); +var getNextDebugID = require('getNextDebugID'); var invariant = require('invariant'); var warning = require('warning'); @@ -56,8 +57,6 @@ function isInternalComponentType(type) { ); } -var nextDebugID = 1; - /** * Given a ReactNode, create an instance that will actually be mounted. * @@ -125,7 +124,7 @@ function instantiateReactComponent(node, shouldHaveDebugID) { instance._mountImage = null; if (__DEV__) { - instance._debugID = shouldHaveDebugID ? nextDebugID++ : 0; + instance._debugID = shouldHaveDebugID ? getNextDebugID() : 0; } // Internal instances should fully constructed at this point, so they should diff --git a/src/shared/utils/getNextDebugID.js b/src/shared/utils/getNextDebugID.js new file mode 100644 index 0000000000000..6e7ecb43b84a6 --- /dev/null +++ b/src/shared/utils/getNextDebugID.js @@ -0,0 +1,21 @@ +/** + * Copyright 2013-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @providesModule getNextDebugID + * @flow + */ + +'use strict'; + +var nextDebugID = 1; + +function getNextDebugID(): number { + return nextDebugID++; +} + +module.exports = getNextDebugID; diff --git a/src/test/ReactShallowRenderer.js b/src/test/ReactShallowRenderer.js index 1517d49cff824..ee50d9d6efc66 100644 --- a/src/test/ReactShallowRenderer.js +++ b/src/test/ReactShallowRenderer.js @@ -20,17 +20,16 @@ var ReactReconciler = require('ReactReconciler'); var ReactUpdates = require('ReactUpdates'); var emptyObject = require('emptyObject'); +var getNextDebugID = require('getNextDebugID'); var invariant = require('invariant'); -var nextDebugID = 1; - class NoopInternalComponent { constructor(element) { this._renderedOutput = element; this._currentElement = element; if (__DEV__) { - this._debugID = nextDebugID++; + this._debugID = getNextDebugID(); } } mountComponent() {} @@ -50,7 +49,7 @@ class NoopInternalComponent { var ShallowComponentWrapper = function(element) { // TODO: Consolidate with instantiateReactComponent if (__DEV__) { - this._debugID = nextDebugID++; + this._debugID = getNextDebugID(); } this.construct(element);