@@ -18,13 +18,16 @@ var ReactElement = require('ReactElement');
1818var ReactEmptyComponent = require ( 'ReactEmptyComponent' ) ;
1919var ReactInstanceHandles = require ( 'ReactInstanceHandles' ) ;
2020var ReactInstanceMap = require ( 'ReactInstanceMap' ) ;
21+ var ReactMarkupChecksum = require ( 'ReactMarkupChecksum' ) ;
2122var ReactPerf = require ( 'ReactPerf' ) ;
23+ var ReactUpdates = require ( 'ReactUpdates' ) ;
2224
2325var containsNode = require ( 'containsNode' ) ;
2426var deprecated = require ( 'deprecated' ) ;
2527var getReactRootElementInContainer = require ( 'getReactRootElementInContainer' ) ;
2628var instantiateReactComponent = require ( 'instantiateReactComponent' ) ;
2729var invariant = require ( 'invariant' ) ;
30+ var setInnerHTML = require ( 'setInnerHTML' ) ;
2831var shouldUpdateReactComponent = require ( 'shouldUpdateReactComponent' ) ;
2932var warning = require ( 'warning' ) ;
3033
@@ -208,6 +211,23 @@ function findDeepestCachedAncestor(targetID) {
208211 return foundNode ;
209212}
210213
214+ /**
215+ * Mounts this component and inserts it into the DOM.
216+ *
217+ * @param {string } rootID DOM ID of the root node.
218+ * @param {DOMElement } container DOM element to mount into.
219+ * @param {ReactReconcileTransaction } transaction
220+ * @param {boolean } shouldReuseMarkup If true, do not insert markup
221+ */
222+ function mountComponentIntoNode (
223+ rootID ,
224+ container ,
225+ transaction ,
226+ shouldReuseMarkup ) {
227+ var markup = this . mountComponent ( rootID , transaction , 0 ) ;
228+ ReactMount . _mountImageIntoNode ( markup , container , shouldReuseMarkup ) ;
229+ }
230+
211231/**
212232 * Mounting is the process of initializing a React component by creatings its
213233 * representative DOM elements and inserting them into a supplied `container`.
@@ -321,11 +341,17 @@ var ReactMount = {
321341 componentInstance ,
322342 container
323343 ) ;
324- componentInstance . mountComponentIntoNode (
344+
345+ var transaction = ReactUpdates . ReactReconcileTransaction . getPooled ( ) ;
346+ transaction . perform (
347+ mountComponentIntoNode ,
348+ componentInstance ,
325349 reactRootID ,
326350 container ,
351+ transaction ,
327352 shouldReuseMarkup
328353 ) ;
354+ ReactUpdates . ReactReconcileTransaction . release ( transaction ) ;
329355
330356 if ( __DEV__ ) {
331357 // Record the root element in case it later gets transplanted.
@@ -684,6 +710,62 @@ var ReactMount = {
684710 ) ;
685711 } ,
686712
713+ _mountImageIntoNode : ReactPerf . measure (
714+ 'ReactMount' ,
715+ '_mountImageIntoNode' ,
716+ function ( markup , container , shouldReuseMarkup ) {
717+ invariant (
718+ container && (
719+ container . nodeType === ELEMENT_NODE_TYPE ||
720+ container . nodeType === DOC_NODE_TYPE
721+ ) ,
722+ 'mountComponentIntoNode(...): Target container is not valid.'
723+ ) ;
724+
725+ if ( shouldReuseMarkup ) {
726+ if ( ReactMarkupChecksum . canReuseMarkup (
727+ markup ,
728+ getReactRootElementInContainer ( container ) ) ) {
729+ return ;
730+ } else {
731+ invariant (
732+ container . nodeType !== DOC_NODE_TYPE ,
733+ 'You\'re trying to render a component to the document using ' +
734+ 'server rendering but the checksum was invalid. This usually ' +
735+ 'means you rendered a different component type or props on ' +
736+ 'the client from the one on the server, or your render() ' +
737+ 'methods are impure. React cannot handle this case due to ' +
738+ 'cross-browser quirks by rendering at the document root. You ' +
739+ 'should look for environment dependent code in your components ' +
740+ 'and ensure the props are the same client and server side.'
741+ ) ;
742+
743+ if ( __DEV__ ) {
744+ console . warn (
745+ 'React attempted to use reuse markup in a container but the ' +
746+ 'checksum was invalid. This generally means that you are ' +
747+ 'using server rendering and the markup generated on the ' +
748+ 'server was not what the client was expecting. React injected ' +
749+ 'new markup to compensate which works but you have lost many ' +
750+ 'of the benefits of server rendering. Instead, figure out ' +
751+ 'why the markup being generated is different on the client ' +
752+ 'or server.'
753+ ) ;
754+ }
755+ }
756+ }
757+
758+ invariant (
759+ container . nodeType !== DOC_NODE_TYPE ,
760+ 'You\'re trying to render a component to the document but ' +
761+ 'you didn\'t use server rendering. We can\'t do this ' +
762+ 'without using server rendering due to cross-browser quirks. ' +
763+ 'See renderComponentToString() for server rendering.'
764+ ) ;
765+
766+ setInnerHTML ( container , markup ) ;
767+ }
768+ ) ,
687769
688770 /**
689771 * React ID utilities.
0 commit comments