From fb17e8ca56a9b7688e7ccad7833d8a805ffc6ad5 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 17 Nov 2014 01:58:48 -0800 Subject: [PATCH] Ensure that all internal instances have consistent properties Use preventExtensions so that we can't add expando properties to internal instances. This ensures that the hidden class is kept more consistent. --- src/browser/ui/ReactDOMComponent.js | 2 ++ src/browser/ui/ReactDOMTextComponent.js | 4 ++++ src/core/ReactComponent.js | 4 ++++ src/core/ReactCompositeComponent.js | 3 +++ src/core/instantiateReactComponent.js | 8 ++++++++ 5 files changed, 21 insertions(+) diff --git a/src/browser/ui/ReactDOMComponent.js b/src/browser/ui/ReactDOMComponent.js index 9ce81b1468..ac932dc90b 100644 --- a/src/browser/ui/ReactDOMComponent.js +++ b/src/browser/ui/ReactDOMComponent.js @@ -147,6 +147,8 @@ function validateDangerousTag(tag) { function ReactDOMComponent(tag) { validateDangerousTag(tag); this._tag = tag; + this._renderedChildren = null; + this._previousStyleCopy = null; } ReactDOMComponent.displayName = 'ReactDOMComponent'; diff --git a/src/browser/ui/ReactDOMTextComponent.js b/src/browser/ui/ReactDOMTextComponent.js index 6e63d9dbac..00e18fb851 100644 --- a/src/browser/ui/ReactDOMTextComponent.js +++ b/src/browser/ui/ReactDOMTextComponent.js @@ -50,6 +50,10 @@ assign(ReactDOMTextComponent.prototype, { // TODO: This is really a ReactText (ReactNode), not a ReactElement this._currentElement = text; this._stringText = '' + text; + + // Properties + this._rootNodeID = null; + this._mountIndex = 0; }, /** diff --git a/src/core/ReactComponent.js b/src/core/ReactComponent.js index 3803f891f5..8822ccb753 100644 --- a/src/core/ReactComponent.js +++ b/src/core/ReactComponent.js @@ -118,6 +118,10 @@ var ReactComponent = { // We keep the old element and a reference to the pending element // to track updates. this._currentElement = element; + + this._rootNodeID = null; + this._mountIndex = 0; + this._mountDepth = 0; }, /** diff --git a/src/core/ReactCompositeComponent.js b/src/core/ReactCompositeComponent.js index bd076698be..1d4c25c9f1 100644 --- a/src/core/ReactCompositeComponent.js +++ b/src/core/ReactCompositeComponent.js @@ -117,8 +117,11 @@ var ReactCompositeComponentMixin = assign({}, this._pendingElement = null; this._pendingState = null; + this._pendingForceUpdate = false; this._compositeLifeCycleState = null; + this._renderedComponent = null; + // Children can be either an array or more than one argument ReactComponent.Mixin.construct.apply(this, arguments); diff --git a/src/core/instantiateReactComponent.js b/src/core/instantiateReactComponent.js index ef5887974d..593f54c432 100644 --- a/src/core/instantiateReactComponent.js +++ b/src/core/instantiateReactComponent.js @@ -118,6 +118,14 @@ function instantiateReactComponent(node, parentCompositeType) { // Sets up the instance. This can probably just move into the constructor now. instance.construct(node); + // Internal instances should fully constructed at this point, so they should + // not get any new fields added to them at this point. + if (__DEV__) { + if (Object.preventExtensions) { + Object.preventExtensions(instance); + } + } + return instance; }