diff --git a/src/renderers/dom/shared/ReactDOMTextComponent.js b/src/renderers/dom/shared/ReactDOMTextComponent.js index 60f3f7a04d535..f66d84da50a7b 100644 --- a/src/renderers/dom/shared/ReactDOMTextComponent.js +++ b/src/renderers/dom/shared/ReactDOMTextComponent.js @@ -18,6 +18,7 @@ var ReactPerf = require('ReactPerf'); var assign = require('Object.assign'); var escapeTextContentForBrowser = require('escapeTextContentForBrowser'); +var invariant = require('invariant'); var validateDOMNesting = require('validateDOMNesting'); /** @@ -46,7 +47,7 @@ var ReactDOMTextComponent = function(text) { // Properties this._domID = null; this._mountIndex = 0; - this._openingComment = null; + this._closingComment = null; this._commentNodes = null; }; @@ -98,8 +99,8 @@ assign(ReactDOMTextComponent.prototype, { ); } DOMLazyTree.queueChild(lazyTree, DOMLazyTree(closingComment)); - this._openingComment = openingComment; - ReactDOMComponentTree.precacheNode(this, closingComment); + ReactDOMComponentTree.precacheNode(this, openingComment); + this._closingComment = closingComment; return lazyTree; } else { var escapedText = escapeTextContentForBrowser(this._stringText); @@ -149,13 +150,29 @@ assign(ReactDOMTextComponent.prototype, { if (nativeNode) { return nativeNode; } - nativeNode = [this._openingComment, this._nativeNode]; + if (!this._closingComment) { + var openingComment = ReactDOMComponentTree.getNodeFromInstance(this); + var node = openingComment.nextSibling; + while (true) { + invariant( + node != null, + 'Missing closing comment for text component %s %s %s', + this._domID, openingComment, node + ); + if (node.nodeType === 8 && node.nodeValue === ' /react-text ') { + this._closingComment = node; + break; + } + node = node.nextSibling; + } + } + nativeNode = [this._nativeNode, this._closingComment]; this._commentNodes = nativeNode; return nativeNode; }, unmountComponent: function() { - this._openingComment = null; + this._closingComment = null; this._commentNodes = null; ReactDOMComponentTree.uncacheNode(this); }, diff --git a/src/test/ReactDefaultPerf.js b/src/test/ReactDefaultPerf.js index 9671e3d4f4529..782f0e30435c8 100644 --- a/src/test/ReactDefaultPerf.js +++ b/src/test/ReactDefaultPerf.js @@ -233,7 +233,7 @@ var ReactDefaultPerf = { // Old node is already unmounted; can't get its instance id = ReactDOMComponentTree.getInstanceFromNode(args[1].node)._rootNodeID; } else if (fnName === 'replaceDelimitedText') { - id = getID(ReactDOMComponentTree.getInstanceFromNode(args[1])); + id = getID(ReactDOMComponentTree.getInstanceFromNode(args[0])); } else if (typeof id === 'object') { id = getID(ReactDOMComponentTree.getInstanceFromNode(args[0])); }