react 0.12.0-rc1 → 0.13.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/JSXTransformer.js +1862 -519
- package/dist/react-with-addons.js +4099 -3299
- package/dist/react-with-addons.min.js +6 -6
- package/dist/react.js +3893 -3353
- package/dist/react.min.js +6 -6
- package/lib/BeforeInputEventPlugin.js +388 -111
- package/lib/CSSProperty.js +5 -2
- package/lib/CSSPropertyOperations.js +20 -0
- package/lib/ChangeEventPlugin.js +2 -2
- package/lib/Danger.js +1 -1
- package/lib/DefaultEventPluginOrder.js +0 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +87 -0
- package/lib/HTMLDOMPropertyConfig.js +7 -0
- package/lib/Object.assign.js +3 -1
- package/lib/React.js +14 -49
- package/lib/ReactBrowserComponentMixin.js +2 -12
- package/lib/ReactBrowserEventEmitter.js +2 -4
- package/lib/ReactCSSTransitionGroup.js +3 -0
- package/lib/ReactCSSTransitionGroupChild.js +8 -0
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactClass.js +916 -0
- package/lib/ReactComponent.js +36 -286
- package/lib/ReactComponentBrowserEnvironment.js +9 -82
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactCompositeComponent.js +608 -1026
- package/lib/ReactContext.js +5 -1
- package/lib/ReactDOM.js +2 -7
- package/lib/ReactDOMButton.js +4 -5
- package/lib/ReactDOMComponent.js +97 -69
- package/lib/ReactDOMForm.js +4 -5
- package/lib/ReactDOMIDOperations.js +55 -73
- package/lib/ReactDOMImg.js +3 -5
- package/lib/ReactDOMInput.js +4 -5
- package/lib/ReactDOMOption.js +4 -5
- package/lib/ReactDOMSelect.js +55 -63
- package/lib/ReactDOMSelection.js +5 -1
- package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +54 -34
- package/lib/ReactDOMTextarea.js +4 -5
- package/lib/ReactDefaultInjection.js +13 -7
- package/lib/ReactDefaultPerf.js +7 -6
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +24 -5
- package/lib/ReactElementValidator.js +101 -52
- package/lib/ReactEmptyComponent.js +17 -10
- package/lib/ReactInjection.js +6 -4
- package/lib/ReactInputSelection.js +2 -3
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactMount.js +193 -64
- package/lib/ReactMultiChild.js +32 -42
- package/lib/ReactNativeComponent.js +46 -9
- package/lib/ReactOwner.js +3 -47
- package/lib/ReactPerf.js +20 -0
- package/lib/ReactPropTransferer.js +0 -55
- package/lib/ReactPropTypes.js +1 -17
- package/lib/ReactRef.js +96 -0
- package/lib/ReactServerRendering.js +3 -2
- package/lib/ReactTestUtils.js +82 -25
- package/lib/ReactTransitionGroup.js +47 -6
- package/lib/ReactUpdates.js +43 -42
- package/lib/SyntheticMouseEvent.js +1 -3
- package/lib/ViewportMetrics.js +1 -4
- package/lib/accumulate.js +47 -0
- package/lib/cloneWithProps.js +2 -2
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +2 -2
- package/lib/findDOMNode.js +52 -0
- package/lib/flattenChildren.js +1 -14
- package/lib/getIteratorFn.js +42 -0
- package/lib/instantiateReactComponent.js +88 -65
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +1 -2
- package/lib/shouldUpdateReactComponent.js +13 -5
- package/lib/traverseAllChildren.js +110 -54
- package/lib/warning.js +1 -1
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -232
- package/lib/deprecated.js +0 -47
package/lib/ReactInjection.js
CHANGED
|
@@ -13,18 +13,20 @@
|
|
|
13
13
|
|
|
14
14
|
var DOMProperty = require("./DOMProperty");
|
|
15
15
|
var EventPluginHub = require("./EventPluginHub");
|
|
16
|
-
var
|
|
17
|
-
var
|
|
16
|
+
var ReactComponentEnvironment = require("./ReactComponentEnvironment");
|
|
17
|
+
var ReactClass = require("./ReactClass");
|
|
18
18
|
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
19
19
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
20
20
|
var ReactNativeComponent = require("./ReactNativeComponent");
|
|
21
|
+
var ReactDOMComponent = require("./ReactDOMComponent");
|
|
21
22
|
var ReactPerf = require("./ReactPerf");
|
|
22
23
|
var ReactRootIndex = require("./ReactRootIndex");
|
|
23
24
|
var ReactUpdates = require("./ReactUpdates");
|
|
24
25
|
|
|
25
26
|
var ReactInjection = {
|
|
26
|
-
Component:
|
|
27
|
-
|
|
27
|
+
Component: ReactComponentEnvironment.injection,
|
|
28
|
+
Class: ReactClass.injection,
|
|
29
|
+
DOMComponent: ReactDOMComponent.injection,
|
|
28
30
|
DOMProperty: DOMProperty.injection,
|
|
29
31
|
EmptyComponent: ReactEmptyComponent.injection,
|
|
30
32
|
EventPluginHub: EventPluginHub.injection,
|
|
@@ -31,9 +31,8 @@ var ReactInputSelection = {
|
|
|
31
31
|
|
|
32
32
|
hasSelectionCapabilities: function(elem) {
|
|
33
33
|
return elem && (
|
|
34
|
-
(elem.nodeName === 'INPUT' && elem.type === 'text') ||
|
|
35
|
-
elem.nodeName === 'TEXTAREA' ||
|
|
36
|
-
elem.contentEditable === 'true'
|
|
34
|
+
((elem.nodeName === 'INPUT' && elem.type === 'text') ||
|
|
35
|
+
elem.nodeName === 'TEXTAREA' || elem.contentEditable === 'true')
|
|
37
36
|
);
|
|
38
37
|
},
|
|
39
38
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-2014, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
* @providesModule ReactInstanceMap
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
"use strict";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
16
|
+
* instance (key) and the internal representation (value). This allows public
|
|
17
|
+
* methods to accept the user facing instance as an argument and map them back
|
|
18
|
+
* to internal methods.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// TODO: Replace this with ES6: var ReactInstanceMap = new Map();
|
|
22
|
+
var ReactInstanceMap = {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This API should be called `delete` but we'd have to make sure to always
|
|
26
|
+
* transform these to strings for IE support. When this transform is fully
|
|
27
|
+
* supported we can rename it.
|
|
28
|
+
*/
|
|
29
|
+
remove: function(key) {
|
|
30
|
+
key._reactInternalInstance = undefined;
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
get: function(key) {
|
|
34
|
+
return key._reactInternalInstance;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
has: function(key) {
|
|
38
|
+
return key._reactInternalInstance !== undefined;
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
set: function(key, value) {
|
|
42
|
+
key._reactInternalInstance = value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = ReactInstanceMap;
|
package/lib/ReactMount.js
CHANGED
|
@@ -15,22 +15,22 @@ var DOMProperty = require("./DOMProperty");
|
|
|
15
15
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
16
16
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
17
17
|
var ReactElement = require("./ReactElement");
|
|
18
|
-
var
|
|
18
|
+
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
19
19
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
20
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
21
|
+
var ReactMarkupChecksum = require("./ReactMarkupChecksum");
|
|
20
22
|
var ReactPerf = require("./ReactPerf");
|
|
23
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
21
24
|
|
|
25
|
+
var emptyObject = require("./emptyObject");
|
|
22
26
|
var containsNode = require("./containsNode");
|
|
23
|
-
var deprecated = require("./deprecated");
|
|
24
27
|
var getReactRootElementInContainer = require("./getReactRootElementInContainer");
|
|
25
28
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
26
29
|
var invariant = require("./invariant");
|
|
30
|
+
var setInnerHTML = require("./setInnerHTML");
|
|
27
31
|
var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
|
|
28
32
|
var warning = require("./warning");
|
|
29
33
|
|
|
30
|
-
var createElement = ReactLegacyElement.wrapCreateElement(
|
|
31
|
-
ReactElement.createElement
|
|
32
|
-
);
|
|
33
|
-
|
|
34
34
|
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
|
35
35
|
|
|
36
36
|
var ATTR_NAME = DOMProperty.ID_ATTRIBUTE_NAME;
|
|
@@ -53,6 +53,22 @@ if ("production" !== process.env.NODE_ENV) {
|
|
|
53
53
|
// Used to store breadth-first search state in findComponentRoot.
|
|
54
54
|
var findComponentRootReusableArray = [];
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Finds the index of the first character
|
|
58
|
+
* that's not common between the two given strings.
|
|
59
|
+
*
|
|
60
|
+
* @return {number} the index of the character where the strings diverge
|
|
61
|
+
*/
|
|
62
|
+
function firstDifferenceIndex(string1, string2) {
|
|
63
|
+
var minLen = Math.min(string1.length, string2.length);
|
|
64
|
+
for (var i = 0; i < minLen; i++) {
|
|
65
|
+
if (string1.charAt(i) !== string2.charAt(i)) {
|
|
66
|
+
return i;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return string1.length === string2.length ? -1 : minLen;
|
|
70
|
+
}
|
|
71
|
+
|
|
56
72
|
/**
|
|
57
73
|
* @param {DOMElement} container DOM element that may contain a React component.
|
|
58
74
|
* @return {?string} A "reactRoot" ID, if a React component is rendered.
|
|
@@ -130,6 +146,24 @@ function getNode(id) {
|
|
|
130
146
|
return nodeCache[id];
|
|
131
147
|
}
|
|
132
148
|
|
|
149
|
+
/**
|
|
150
|
+
* Finds the node with the supplied public React instance.
|
|
151
|
+
*
|
|
152
|
+
* @param {*} instance A public React instance.
|
|
153
|
+
* @return {?DOMElement} DOM node with the suppled `id`.
|
|
154
|
+
* @internal
|
|
155
|
+
*/
|
|
156
|
+
function getNodeFromInstance(instance) {
|
|
157
|
+
var id = ReactInstanceMap.get(instance)._rootNodeID;
|
|
158
|
+
if (ReactEmptyComponent.isNullComponentID(id)) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
if (!nodeCache.hasOwnProperty(id) || !isValid(nodeCache[id], id)) {
|
|
162
|
+
nodeCache[id] = ReactMount.findReactNodeByID(id);
|
|
163
|
+
}
|
|
164
|
+
return nodeCache[id];
|
|
165
|
+
}
|
|
166
|
+
|
|
133
167
|
/**
|
|
134
168
|
* A node is "valid" if it is contained by a currently mounted container.
|
|
135
169
|
*
|
|
@@ -193,6 +227,24 @@ function findDeepestCachedAncestor(targetID) {
|
|
|
193
227
|
return foundNode;
|
|
194
228
|
}
|
|
195
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Mounts this component and inserts it into the DOM.
|
|
232
|
+
*
|
|
233
|
+
* @param {string} rootID DOM ID of the root node.
|
|
234
|
+
* @param {DOMElement} container DOM element to mount into.
|
|
235
|
+
* @param {ReactReconcileTransaction} transaction
|
|
236
|
+
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
237
|
+
*/
|
|
238
|
+
function mountComponentIntoNode(
|
|
239
|
+
rootID,
|
|
240
|
+
container,
|
|
241
|
+
transaction,
|
|
242
|
+
shouldReuseMarkup) {
|
|
243
|
+
var markup = this.mountComponent(rootID, transaction, emptyObject);
|
|
244
|
+
this._isTopLevel = true;
|
|
245
|
+
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
246
|
+
}
|
|
247
|
+
|
|
196
248
|
/**
|
|
197
249
|
* Mounting is the process of initializing a React component by creatings its
|
|
198
250
|
* representative DOM elements and inserting them into a supplied `container`.
|
|
@@ -230,16 +282,16 @@ var ReactMount = {
|
|
|
230
282
|
/**
|
|
231
283
|
* Take a component that's already mounted into the DOM and replace its props
|
|
232
284
|
* @param {ReactComponent} prevComponent component instance already in the DOM
|
|
233
|
-
* @param {
|
|
285
|
+
* @param {ReactElement} nextElement component instance to render
|
|
234
286
|
* @param {DOMElement} container container to render into
|
|
235
287
|
* @param {?function} callback function triggered on completion
|
|
236
288
|
*/
|
|
237
289
|
_updateRootComponent: function(
|
|
238
290
|
prevComponent,
|
|
239
|
-
|
|
291
|
+
nextElement,
|
|
240
292
|
container,
|
|
241
293
|
callback) {
|
|
242
|
-
var nextProps =
|
|
294
|
+
var nextProps = nextElement.props;
|
|
243
295
|
ReactMount.scrollMonitor(container, function() {
|
|
244
296
|
prevComponent.replaceProps(nextProps, callback);
|
|
245
297
|
});
|
|
@@ -263,13 +315,11 @@ var ReactMount = {
|
|
|
263
315
|
_registerComponent: function(nextComponent, container) {
|
|
264
316
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
265
317
|
container && (
|
|
266
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
267
|
-
container.nodeType === DOC_NODE_TYPE
|
|
318
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
268
319
|
),
|
|
269
320
|
'_registerComponent(...): Target container is not a DOM element.'
|
|
270
321
|
) : invariant(container && (
|
|
271
|
-
container.nodeType === ELEMENT_NODE_TYPE ||
|
|
272
|
-
container.nodeType === DOC_NODE_TYPE
|
|
322
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
273
323
|
)));
|
|
274
324
|
|
|
275
325
|
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
|
|
@@ -286,44 +336,47 @@ var ReactMount = {
|
|
|
286
336
|
* @param {boolean} shouldReuseMarkup if we should skip the markup insertion
|
|
287
337
|
* @return {ReactComponent} nextComponent
|
|
288
338
|
*/
|
|
289
|
-
_renderNewRootComponent:
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
'componentDidUpdate.'
|
|
305
|
-
) : null);
|
|
306
|
-
|
|
307
|
-
var componentInstance = instantiateReactComponent(nextComponent, null);
|
|
308
|
-
var reactRootID = ReactMount._registerComponent(
|
|
309
|
-
componentInstance,
|
|
310
|
-
container
|
|
311
|
-
);
|
|
312
|
-
componentInstance.mountComponentIntoNode(
|
|
313
|
-
reactRootID,
|
|
314
|
-
container,
|
|
315
|
-
shouldReuseMarkup
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
319
|
-
// Record the root element in case it later gets transplanted.
|
|
320
|
-
rootElementsByReactRootID[reactRootID] =
|
|
321
|
-
getReactRootElementInContainer(container);
|
|
322
|
-
}
|
|
339
|
+
_renderNewRootComponent: function(
|
|
340
|
+
nextComponent,
|
|
341
|
+
container,
|
|
342
|
+
shouldReuseMarkup
|
|
343
|
+
) {
|
|
344
|
+
// Various parts of our code (such as ReactCompositeComponent's
|
|
345
|
+
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
346
|
+
// verify that that's the case.
|
|
347
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
348
|
+
ReactCurrentOwner.current == null,
|
|
349
|
+
'_renderNewRootComponent(): Render methods should be a pure function ' +
|
|
350
|
+
'of props and state; triggering nested component updates from ' +
|
|
351
|
+
'render is not allowed. If necessary, trigger nested updates in ' +
|
|
352
|
+
'componentDidUpdate.'
|
|
353
|
+
) : null);
|
|
323
354
|
|
|
324
|
-
|
|
355
|
+
var componentInstance = instantiateReactComponent(nextComponent, null);
|
|
356
|
+
var reactRootID = ReactMount._registerComponent(
|
|
357
|
+
componentInstance,
|
|
358
|
+
container
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
362
|
+
transaction.perform(
|
|
363
|
+
mountComponentIntoNode,
|
|
364
|
+
componentInstance,
|
|
365
|
+
reactRootID,
|
|
366
|
+
container,
|
|
367
|
+
transaction,
|
|
368
|
+
shouldReuseMarkup
|
|
369
|
+
);
|
|
370
|
+
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
371
|
+
|
|
372
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
373
|
+
// Record the root element in case it later gets transplanted.
|
|
374
|
+
rootElementsByReactRootID[reactRootID] =
|
|
375
|
+
getReactRootElementInContainer(container);
|
|
325
376
|
}
|
|
326
|
-
|
|
377
|
+
|
|
378
|
+
return componentInstance;
|
|
379
|
+
},
|
|
327
380
|
|
|
328
381
|
/**
|
|
329
382
|
* Renders a React component into the DOM in the supplied `container`.
|
|
@@ -340,16 +393,16 @@ var ReactMount = {
|
|
|
340
393
|
render: function(nextElement, container, callback) {
|
|
341
394
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
342
395
|
ReactElement.isValidElement(nextElement),
|
|
343
|
-
'
|
|
396
|
+
'React.render(): Invalid component element.%s',
|
|
344
397
|
(
|
|
345
398
|
typeof nextElement === 'string' ?
|
|
346
399
|
' Instead of passing an element string, make sure to instantiate ' +
|
|
347
400
|
'it by passing it to React.createElement.' :
|
|
348
|
-
|
|
401
|
+
typeof nextElement === 'function' ?
|
|
349
402
|
' Instead of passing a component class, make sure to instantiate ' +
|
|
350
403
|
'it by passing it to React.createElement.' :
|
|
351
|
-
// Check if it quacks like
|
|
352
|
-
|
|
404
|
+
// Check if it quacks like an element
|
|
405
|
+
nextElement != null && nextElement.props !== undefined ?
|
|
353
406
|
' This may be caused by unintentionally loading two independent ' +
|
|
354
407
|
'copies of React.' :
|
|
355
408
|
''
|
|
@@ -366,7 +419,7 @@ var ReactMount = {
|
|
|
366
419
|
nextElement,
|
|
367
420
|
container,
|
|
368
421
|
callback
|
|
369
|
-
);
|
|
422
|
+
).getPublicInstance();
|
|
370
423
|
} else {
|
|
371
424
|
ReactMount.unmountComponentAtNode(container);
|
|
372
425
|
}
|
|
@@ -382,7 +435,7 @@ var ReactMount = {
|
|
|
382
435
|
nextElement,
|
|
383
436
|
container,
|
|
384
437
|
shouldReuseMarkup
|
|
385
|
-
);
|
|
438
|
+
).getPublicInstance();
|
|
386
439
|
callback && callback.call(component);
|
|
387
440
|
return component;
|
|
388
441
|
},
|
|
@@ -397,7 +450,7 @@ var ReactMount = {
|
|
|
397
450
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
398
451
|
*/
|
|
399
452
|
constructAndRenderComponent: function(constructor, props, container) {
|
|
400
|
-
var element = createElement(constructor, props);
|
|
453
|
+
var element = ReactElement.createElement(constructor, props);
|
|
401
454
|
return ReactMount.render(element, container);
|
|
402
455
|
},
|
|
403
456
|
|
|
@@ -462,6 +515,15 @@ var ReactMount = {
|
|
|
462
515
|
'componentDidUpdate.'
|
|
463
516
|
) : null);
|
|
464
517
|
|
|
518
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
519
|
+
container && (
|
|
520
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
521
|
+
),
|
|
522
|
+
'unmountComponentAtNode(...): Target container is not a DOM element.'
|
|
523
|
+
) : invariant(container && (
|
|
524
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
525
|
+
)));
|
|
526
|
+
|
|
465
527
|
var reactRootID = getReactRootID(container);
|
|
466
528
|
var component = instancesByReactRootID[reactRootID];
|
|
467
529
|
if (!component) {
|
|
@@ -666,6 +728,75 @@ var ReactMount = {
|
|
|
666
728
|
) : invariant(false));
|
|
667
729
|
},
|
|
668
730
|
|
|
731
|
+
_mountImageIntoNode: function(markup, container, shouldReuseMarkup) {
|
|
732
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
733
|
+
container && (
|
|
734
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
735
|
+
),
|
|
736
|
+
'mountComponentIntoNode(...): Target container is not valid.'
|
|
737
|
+
) : invariant(container && (
|
|
738
|
+
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
739
|
+
)));
|
|
740
|
+
|
|
741
|
+
if (shouldReuseMarkup) {
|
|
742
|
+
var rootElement = getReactRootElementInContainer(container);
|
|
743
|
+
if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
|
|
744
|
+
return;
|
|
745
|
+
} else {
|
|
746
|
+
var checksum = rootElement.getAttribute(
|
|
747
|
+
ReactMarkupChecksum.CHECKSUM_ATTR_NAME
|
|
748
|
+
);
|
|
749
|
+
rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
750
|
+
|
|
751
|
+
var rootMarkup = rootElement.outerHTML;
|
|
752
|
+
rootElement.setAttribute(
|
|
753
|
+
ReactMarkupChecksum.CHECKSUM_ATTR_NAME,
|
|
754
|
+
checksum
|
|
755
|
+
);
|
|
756
|
+
|
|
757
|
+
var diffIndex = firstDifferenceIndex(markup, rootMarkup);
|
|
758
|
+
var difference = ' (client) ' +
|
|
759
|
+
markup.substring(diffIndex - 20, diffIndex + 20) +
|
|
760
|
+
'\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
|
|
761
|
+
|
|
762
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
763
|
+
container.nodeType !== DOC_NODE_TYPE,
|
|
764
|
+
'You\'re trying to render a component to the document using ' +
|
|
765
|
+
'server rendering but the checksum was invalid. This usually ' +
|
|
766
|
+
'means you rendered a different component type or props on ' +
|
|
767
|
+
'the client from the one on the server, or your render() ' +
|
|
768
|
+
'methods are impure. React cannot handle this case due to ' +
|
|
769
|
+
'cross-browser quirks by rendering at the document root. You ' +
|
|
770
|
+
'should look for environment dependent code in your components ' +
|
|
771
|
+
'and ensure the props are the same client and server side:\n%s',
|
|
772
|
+
difference
|
|
773
|
+
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
774
|
+
|
|
775
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
776
|
+
console.warn(
|
|
777
|
+
'React attempted to use reuse markup in a container but the ' +
|
|
778
|
+
'checksum was invalid. This generally means that you are ' +
|
|
779
|
+
'using server rendering and the markup generated on the ' +
|
|
780
|
+
'server was not what the client was expecting. React injected ' +
|
|
781
|
+
'new markup to compensate which works but you have lost many ' +
|
|
782
|
+
'of the benefits of server rendering. Instead, figure out ' +
|
|
783
|
+
'why the markup being generated is different on the client ' +
|
|
784
|
+
'or server:\n' + difference
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
791
|
+
container.nodeType !== DOC_NODE_TYPE,
|
|
792
|
+
'You\'re trying to render a component to the document but ' +
|
|
793
|
+
'you didn\'t use server rendering. We can\'t do this ' +
|
|
794
|
+
'without using server rendering due to cross-browser quirks. ' +
|
|
795
|
+
'See React.renderToString() for server rendering.'
|
|
796
|
+
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
797
|
+
|
|
798
|
+
setInnerHTML(container, markup);
|
|
799
|
+
},
|
|
669
800
|
|
|
670
801
|
/**
|
|
671
802
|
* React ID utilities.
|
|
@@ -679,16 +810,14 @@ var ReactMount = {
|
|
|
679
810
|
|
|
680
811
|
getNode: getNode,
|
|
681
812
|
|
|
813
|
+
getNodeFromInstance: getNodeFromInstance,
|
|
814
|
+
|
|
682
815
|
purgeID: purgeID
|
|
683
816
|
};
|
|
684
817
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
'
|
|
688
|
-
|
|
689
|
-
'render',
|
|
690
|
-
this,
|
|
691
|
-
ReactMount.render
|
|
692
|
-
);
|
|
818
|
+
ReactPerf.measureMethods(ReactMount, 'ReactMount', {
|
|
819
|
+
_renderNewRootComponent: '_renderNewRootComponent',
|
|
820
|
+
_mountImageIntoNode: '_mountImageIntoNode'
|
|
821
|
+
});
|
|
693
822
|
|
|
694
823
|
module.exports = ReactMount;
|