react 0.13.3 → 0.14.0-beta1
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/README.md +5 -2
- package/addons.js +7 -0
- package/dist/JSXTransformer.js +4101 -2432
- package/dist/react-with-addons.js +4389 -6277
- package/dist/react-with-addons.min.js +6 -8
- package/dist/react.js +4028 -5697
- package/dist/react.min.js +5 -6
- package/lib/{AutoFocusMixin.js → AutoFocusUtils.js} +16 -5
- package/lib/BeforeInputEventPlugin.js +30 -118
- package/lib/CSSCore.js +12 -23
- package/lib/CSSProperty.js +4 -3
- package/lib/CSSPropertyOperations.js +14 -30
- package/lib/CallbackQueue.js +7 -10
- package/lib/ChangeEventPlugin.js +26 -88
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +13 -33
- package/lib/DOMProperty.js +86 -147
- package/lib/DOMPropertyOperations.js +91 -67
- package/lib/Danger.js +19 -62
- package/lib/DefaultEventPluginOrder.js +2 -12
- package/lib/EnterLeaveEventPlugin.js +11 -33
- package/lib/EventConstants.js +2 -2
- package/lib/EventListener.js +11 -13
- package/lib/EventPluginHub.js +44 -47
- package/lib/EventPluginRegistry.js +18 -74
- package/lib/EventPluginUtils.js +33 -44
- package/lib/EventPropagators.js +23 -26
- package/lib/ExecutionEnvironment.js +4 -8
- package/lib/FallbackCompositionState.js +3 -3
- package/lib/HTMLDOMPropertyConfig.js +15 -20
- package/lib/LinkedStateMixin.js +3 -6
- package/lib/LinkedValueUtils.js +71 -89
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +20 -11
- package/lib/React.js +9 -129
- package/lib/ReactBrowserComponentMixin.js +9 -2
- package/lib/ReactBrowserEventEmitter.js +26 -82
- package/lib/ReactCSSTransitionGroup.js +13 -24
- package/lib/ReactCSSTransitionGroupChild.js +26 -28
- package/lib/ReactChildReconciler.js +11 -19
- package/lib/ReactChildren.js +24 -31
- package/lib/ReactClass.js +96 -267
- package/lib/ReactComponent.js +28 -57
- package/lib/ReactComponentBrowserEnvironment.js +4 -8
- package/lib/ReactComponentEnvironment.js +6 -12
- package/lib/ReactComponentWithPureRenderMixin.js +6 -7
- package/lib/ReactCompositeComponent.js +115 -381
- package/lib/ReactCurrentOwner.js +1 -3
- package/lib/ReactDOM.js +4 -2
- package/lib/ReactDOMButton.js +16 -28
- package/lib/ReactDOMClient.js +90 -0
- package/lib/ReactDOMComponent.js +468 -156
- package/lib/ReactDOMIDOperations.js +25 -22
- package/lib/ReactDOMInput.js +79 -108
- package/lib/ReactDOMOption.js +58 -20
- package/lib/ReactDOMSelect.js +95 -83
- package/lib/ReactDOMSelection.js +5 -20
- package/lib/ReactDOMServer.js +24 -0
- package/lib/ReactDOMTextComponent.js +17 -18
- package/lib/ReactDOMTextarea.js +44 -69
- package/lib/ReactDefaultBatchingStrategy.js +9 -13
- package/lib/ReactDefaultInjection.js +20 -76
- package/lib/ReactDefaultPerf.js +36 -69
- package/lib/ReactDefaultPerfAnalysis.js +8 -14
- package/lib/ReactElement.js +26 -120
- package/lib/ReactElementValidator.js +56 -192
- package/lib/ReactEmptyComponent.js +7 -11
- package/lib/ReactErrorUtils.js +3 -3
- package/lib/ReactEventEmitterMixin.js +3 -13
- package/lib/ReactEventListener.js +58 -40
- package/lib/ReactFragment.js +33 -59
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +14 -23
- package/lib/ReactInstanceHandles.js +29 -58
- package/lib/ReactInstanceMap.js +5 -5
- package/lib/ReactIsomorphic.js +70 -0
- package/lib/ReactLink.js +2 -4
- package/lib/ReactMarkupChecksum.js +5 -10
- package/lib/ReactMount.js +142 -285
- package/lib/ReactMultiChild.js +19 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +6 -15
- package/lib/ReactNoopUpdateQueue.js +118 -0
- package/lib/ReactOwner.js +7 -24
- package/lib/ReactPerf.js +8 -12
- package/lib/ReactPropTransferer.js +4 -4
- package/lib/ReactPropTypeLocationNames.js +2 -2
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +41 -61
- package/lib/ReactReconcileTransaction.js +11 -36
- package/lib/ReactReconciler.js +14 -26
- package/lib/ReactRef.js +5 -8
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerBatchingStrategy.js +23 -0
- package/lib/ReactServerRendering.js +20 -15
- package/lib/ReactServerRenderingTransaction.js +9 -34
- package/lib/ReactStateSetters.js +6 -6
- package/lib/ReactTestUtils.js +137 -190
- package/lib/ReactTransitionChildMapping.js +5 -7
- package/lib/ReactTransitionEvents.js +5 -5
- package/lib/ReactTransitionGroup.js +30 -52
- package/lib/ReactUpdateQueue.js +69 -107
- package/lib/ReactUpdates.js +26 -81
- package/lib/ReactWithAddons.js +5 -6
- package/lib/SVGDOMPropertyConfig.js +39 -4
- package/lib/SelectEventPlugin.js +31 -33
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +138 -130
- package/lib/SyntheticClipboardEvent.js +5 -9
- package/lib/SyntheticCompositionEvent.js +4 -10
- package/lib/SyntheticDragEvent.js +3 -3
- package/lib/SyntheticEvent.js +14 -15
- package/lib/SyntheticFocusEvent.js +3 -3
- package/lib/SyntheticInputEvent.js +4 -10
- package/lib/SyntheticKeyboardEvent.js +6 -6
- package/lib/SyntheticMouseEvent.js +10 -16
- package/lib/SyntheticTouchEvent.js +3 -3
- package/lib/SyntheticUIEvent.js +5 -5
- package/lib/SyntheticWheelEvent.js +13 -17
- package/lib/Transaction.js +22 -28
- package/lib/ViewportMetrics.js +2 -2
- package/lib/accumulateInto.js +2 -5
- package/lib/adler32.js +2 -4
- package/lib/camelize.js +4 -2
- package/lib/camelizeStyleName.js +2 -2
- package/lib/cloneWithProps.js +6 -12
- package/lib/containsNode.js +29 -16
- package/lib/createArrayFromMixed.js +17 -16
- package/lib/createNodesFromMarkup.js +6 -8
- package/lib/dangerousStyleValue.js +2 -3
- package/lib/deprecated.js +47 -0
- package/lib/emptyFunction.js +10 -4
- package/lib/emptyObject.js +1 -1
- package/lib/escapeTextContentForBrowser.js +1 -1
- package/lib/findDOMNode.js +7 -27
- package/lib/flattenChildren.js +4 -10
- package/lib/focusNode.js +2 -3
- package/lib/forEachAccumulated.js +3 -3
- package/lib/getActiveElement.js +4 -2
- package/lib/getEventCharCode.js +2 -2
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -2
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +2 -4
- package/lib/getMarkupWrap.js +18 -40
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getTextContentAccessor.js +2 -4
- package/lib/getUnboundedScrollPosition.js +1 -1
- package/lib/hyphenate.js +3 -1
- package/lib/hyphenateStyleName.js +2 -2
- package/lib/instantiateReactComponent.js +23 -43
- package/lib/invariant.js +8 -12
- package/lib/isEventSupported.js +7 -10
- package/lib/isNode.js +4 -6
- package/lib/isTextInputElement.js +3 -4
- package/lib/isTextNode.js +3 -1
- package/lib/joinClasses.js +3 -3
- package/lib/keyMirror.js +3 -6
- package/lib/keyOf.js +4 -3
- package/lib/mapObject.js +1 -1
- package/lib/memoizeStringOnly.js +2 -2
- package/lib/onlyChild.js +2 -5
- package/lib/performance.js +2 -5
- package/lib/performanceNow.js +3 -1
- package/lib/quoteAttributeValueForBrowser.js +1 -1
- package/lib/renderSubtreeIntoContainer.js +16 -0
- package/lib/setInnerHTML.js +11 -8
- package/lib/setTextContent.js +3 -3
- package/lib/shallowCompare.js +24 -0
- package/lib/shallowEqual.js +17 -11
- package/lib/shouldUpdateReactComponent.js +3 -64
- package/lib/toArray.js +8 -19
- package/lib/traverseAllChildren.js +23 -90
- package/lib/update.js +25 -85
- package/lib/validateDOMNesting.js +363 -0
- package/lib/warning.js +15 -17
- package/package.json +3 -3
- package/react.js +53 -1
- package/lib/LocalEventTrapMixin.js +0 -53
- package/lib/MobileSafariClickEventPlugin.js +0 -56
- package/lib/ReactContext.js +0 -74
- package/lib/ReactDOMForm.js +0 -47
- package/lib/ReactDOMIframe.js +0 -43
- package/lib/ReactDOMImg.js +0 -44
- package/lib/ReactLifeCycle.js +0 -35
- package/lib/ReactPutListenerQueue.js +0 -54
- package/lib/createFullPageComponent.js +0 -58
- package/lib/cx.js +0 -52
- package/lib/getReactRootElementInContainer.js +0 -33
package/lib/ReactInstanceMap.js
CHANGED
|
@@ -26,22 +26,22 @@ var ReactInstanceMap = {
|
|
|
26
26
|
* transform these to strings for IE support. When this transform is fully
|
|
27
27
|
* supported we can rename it.
|
|
28
28
|
*/
|
|
29
|
-
remove: function(key) {
|
|
29
|
+
remove: function (key) {
|
|
30
30
|
key._reactInternalInstance = undefined;
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
get: function(key) {
|
|
33
|
+
get: function (key) {
|
|
34
34
|
return key._reactInternalInstance;
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
has: function(key) {
|
|
37
|
+
has: function (key) {
|
|
38
38
|
return key._reactInternalInstance !== undefined;
|
|
39
39
|
},
|
|
40
40
|
|
|
41
|
-
set: function(key, value) {
|
|
41
|
+
set: function (key, value) {
|
|
42
42
|
key._reactInternalInstance = value;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
module.exports = ReactInstanceMap;
|
|
47
|
+
module.exports = ReactInstanceMap;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-2015, 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 ReactIsomorphic
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactChildren = require("./ReactChildren");
|
|
15
|
+
var ReactComponent = require("./ReactComponent");
|
|
16
|
+
var ReactClass = require("./ReactClass");
|
|
17
|
+
var ReactDOM = require("./ReactDOM");
|
|
18
|
+
var ReactElement = require("./ReactElement");
|
|
19
|
+
var ReactElementValidator = require("./ReactElementValidator");
|
|
20
|
+
var ReactPropTypes = require("./ReactPropTypes");
|
|
21
|
+
|
|
22
|
+
var assign = require("./Object.assign");
|
|
23
|
+
var onlyChild = require("./onlyChild");
|
|
24
|
+
|
|
25
|
+
var createElement = ReactElement.createElement;
|
|
26
|
+
var createFactory = ReactElement.createFactory;
|
|
27
|
+
var cloneElement = ReactElement.cloneElement;
|
|
28
|
+
|
|
29
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
30
|
+
createElement = ReactElementValidator.createElement;
|
|
31
|
+
createFactory = ReactElementValidator.createFactory;
|
|
32
|
+
cloneElement = ReactElementValidator.cloneElement;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var React = {
|
|
36
|
+
|
|
37
|
+
// Modern
|
|
38
|
+
|
|
39
|
+
Children: {
|
|
40
|
+
map: ReactChildren.map,
|
|
41
|
+
forEach: ReactChildren.forEach,
|
|
42
|
+
count: ReactChildren.count,
|
|
43
|
+
only: onlyChild
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
Component: ReactComponent,
|
|
47
|
+
|
|
48
|
+
createElement: createElement,
|
|
49
|
+
cloneElement: cloneElement,
|
|
50
|
+
isValidElement: ReactElement.isValidElement,
|
|
51
|
+
|
|
52
|
+
// Classic
|
|
53
|
+
|
|
54
|
+
PropTypes: ReactPropTypes,
|
|
55
|
+
createClass: ReactClass.createClass,
|
|
56
|
+
createFactory: createFactory,
|
|
57
|
+
createMixin: function (mixin) {
|
|
58
|
+
// Currently a noop. Will be used to validate and trace mixins.
|
|
59
|
+
return mixin;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// This looks DOM specific but these are actually isomorphic helpers
|
|
63
|
+
// since they are just generating DOM strings.
|
|
64
|
+
DOM: ReactDOM,
|
|
65
|
+
|
|
66
|
+
// Hook for JSX spread, don't use this for anything else.
|
|
67
|
+
__spread: assign
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = React;
|
package/lib/ReactLink.js
CHANGED
|
@@ -56,9 +56,7 @@ function ReactLink(value, requestChange) {
|
|
|
56
56
|
*/
|
|
57
57
|
function createLinkTypeChecker(linkType) {
|
|
58
58
|
var shapes = {
|
|
59
|
-
value: typeof linkType === 'undefined' ?
|
|
60
|
-
React.PropTypes.any.isRequired :
|
|
61
|
-
linkType.isRequired,
|
|
59
|
+
value: typeof linkType === 'undefined' ? React.PropTypes.any.isRequired : linkType.isRequired,
|
|
62
60
|
requestChange: React.PropTypes.func.isRequired
|
|
63
61
|
};
|
|
64
62
|
return React.PropTypes.shape(shapes);
|
|
@@ -68,4 +66,4 @@ ReactLink.PropTypes = {
|
|
|
68
66
|
link: createLinkTypeChecker
|
|
69
67
|
};
|
|
70
68
|
|
|
71
|
-
module.exports = ReactLink;
|
|
69
|
+
module.exports = ReactLink;
|
|
@@ -20,12 +20,9 @@ var ReactMarkupChecksum = {
|
|
|
20
20
|
* @param {string} markup Markup string
|
|
21
21
|
* @return {string} Markup string with checksum attribute attached
|
|
22
22
|
*/
|
|
23
|
-
addChecksumToMarkup: function(markup) {
|
|
23
|
+
addChecksumToMarkup: function (markup) {
|
|
24
24
|
var checksum = adler32(markup);
|
|
25
|
-
return markup.replace(
|
|
26
|
-
'>',
|
|
27
|
-
' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '">'
|
|
28
|
-
);
|
|
25
|
+
return markup.replace('>', ' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '">');
|
|
29
26
|
},
|
|
30
27
|
|
|
31
28
|
/**
|
|
@@ -33,14 +30,12 @@ var ReactMarkupChecksum = {
|
|
|
33
30
|
* @param {DOMElement} element root React element
|
|
34
31
|
* @returns {boolean} whether or not the markup is the same
|
|
35
32
|
*/
|
|
36
|
-
canReuseMarkup: function(markup, element) {
|
|
37
|
-
var existingChecksum = element.getAttribute(
|
|
38
|
-
ReactMarkupChecksum.CHECKSUM_ATTR_NAME
|
|
39
|
-
);
|
|
33
|
+
canReuseMarkup: function (markup, element) {
|
|
34
|
+
var existingChecksum = element.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
40
35
|
existingChecksum = existingChecksum && parseInt(existingChecksum, 10);
|
|
41
36
|
var markupChecksum = adler32(markup);
|
|
42
37
|
return markupChecksum === existingChecksum;
|
|
43
38
|
}
|
|
44
39
|
};
|
|
45
40
|
|
|
46
|
-
module.exports = ReactMarkupChecksum;
|
|
41
|
+
module.exports = ReactMarkupChecksum;
|
package/lib/ReactMount.js
CHANGED
|
@@ -15,7 +15,6 @@ var DOMProperty = require("./DOMProperty");
|
|
|
15
15
|
var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
|
|
16
16
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
17
17
|
var ReactElement = require("./ReactElement");
|
|
18
|
-
var ReactElementValidator = require("./ReactElementValidator");
|
|
19
18
|
var ReactEmptyComponent = require("./ReactEmptyComponent");
|
|
20
19
|
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
21
20
|
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
@@ -27,11 +26,11 @@ var ReactUpdates = require("./ReactUpdates");
|
|
|
27
26
|
|
|
28
27
|
var emptyObject = require("./emptyObject");
|
|
29
28
|
var containsNode = require("./containsNode");
|
|
30
|
-
var getReactRootElementInContainer = require("./getReactRootElementInContainer");
|
|
31
29
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
32
30
|
var invariant = require("./invariant");
|
|
33
31
|
var setInnerHTML = require("./setInnerHTML");
|
|
34
32
|
var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
|
|
33
|
+
var validateDOMNesting = require("./validateDOMNesting");
|
|
35
34
|
var warning = require("./warning");
|
|
36
35
|
|
|
37
36
|
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
|
@@ -41,6 +40,7 @@ var nodeCache = {};
|
|
|
41
40
|
|
|
42
41
|
var ELEMENT_NODE_TYPE = 1;
|
|
43
42
|
var DOC_NODE_TYPE = 9;
|
|
43
|
+
var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
|
|
44
44
|
|
|
45
45
|
/** Mapping from reactRootID to React component instance. */
|
|
46
46
|
var instancesByReactRootID = {};
|
|
@@ -48,7 +48,7 @@ var instancesByReactRootID = {};
|
|
|
48
48
|
/** Mapping from reactRootID to `container` nodes. */
|
|
49
49
|
var containersByReactRootID = {};
|
|
50
50
|
|
|
51
|
-
if (
|
|
51
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
52
52
|
/** __DEV__-only mapping from reactRootID to root elements. */
|
|
53
53
|
var rootElementsByReactRootID = {};
|
|
54
54
|
}
|
|
@@ -72,6 +72,23 @@ function firstDifferenceIndex(string1, string2) {
|
|
|
72
72
|
return string1.length === string2.length ? -1 : minLen;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @param {DOMElement|DOMDocument} container DOM element that may contain
|
|
77
|
+
* a React component
|
|
78
|
+
* @return {?*} DOM element that may have the reactRoot ID, or null.
|
|
79
|
+
*/
|
|
80
|
+
function getReactRootElementInContainer(container) {
|
|
81
|
+
if (!container) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (container.nodeType === DOC_NODE_TYPE) {
|
|
86
|
+
return container.documentElement;
|
|
87
|
+
} else {
|
|
88
|
+
return container.firstChild;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
75
92
|
/**
|
|
76
93
|
* @param {DOMElement} container DOM element that may contain a React component.
|
|
77
94
|
* @return {?string} A "reactRoot" ID, if a React component is rendered.
|
|
@@ -97,11 +114,7 @@ function getID(node) {
|
|
|
97
114
|
if (nodeCache.hasOwnProperty(id)) {
|
|
98
115
|
var cached = nodeCache[id];
|
|
99
116
|
if (cached !== node) {
|
|
100
|
-
(
|
|
101
|
-
!isValid(cached, id),
|
|
102
|
-
'ReactMount: Two valid but unequal nodes with the same `%s`: %s',
|
|
103
|
-
ATTR_NAME, id
|
|
104
|
-
) : invariant(!isValid(cached, id)));
|
|
117
|
+
!!isValid(cached, id) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'ReactMount: Two valid but unequal nodes with the same `%s`: %s', ATTR_NAME, id) : invariant(false) : undefined;
|
|
105
118
|
|
|
106
119
|
nodeCache[id] = node;
|
|
107
120
|
}
|
|
@@ -179,11 +192,7 @@ function getNodeFromInstance(instance) {
|
|
|
179
192
|
*/
|
|
180
193
|
function isValid(node, id) {
|
|
181
194
|
if (node) {
|
|
182
|
-
(
|
|
183
|
-
internalGetID(node) === id,
|
|
184
|
-
'ReactMount: Unexpected modification of `%s`',
|
|
185
|
-
ATTR_NAME
|
|
186
|
-
) : invariant(internalGetID(node) === id));
|
|
195
|
+
!(internalGetID(node) === id) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'ReactMount: Unexpected modification of `%s`', ATTR_NAME) : invariant(false) : undefined;
|
|
187
196
|
|
|
188
197
|
var container = ReactMount.findReactContainerForID(id);
|
|
189
198
|
if (container && containsNode(container, node)) {
|
|
@@ -220,10 +229,7 @@ function findDeepestCachedAncestorImpl(ancestorID) {
|
|
|
220
229
|
*/
|
|
221
230
|
function findDeepestCachedAncestor(targetID) {
|
|
222
231
|
deepestNodeSoFar = null;
|
|
223
|
-
ReactInstanceHandles.traverseAncestors(
|
|
224
|
-
targetID,
|
|
225
|
-
findDeepestCachedAncestorImpl
|
|
226
|
-
);
|
|
232
|
+
ReactInstanceHandles.traverseAncestors(targetID, findDeepestCachedAncestorImpl);
|
|
227
233
|
|
|
228
234
|
var foundNode = deepestNodeSoFar;
|
|
229
235
|
deepestNodeSoFar = null;
|
|
@@ -239,16 +245,16 @@ function findDeepestCachedAncestor(targetID) {
|
|
|
239
245
|
* @param {ReactReconcileTransaction} transaction
|
|
240
246
|
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
241
247
|
*/
|
|
242
|
-
function mountComponentIntoNode(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
);
|
|
251
|
-
componentInstance.
|
|
248
|
+
function mountComponentIntoNode(componentInstance, rootID, container, transaction, shouldReuseMarkup, context) {
|
|
249
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
250
|
+
if (context === emptyObject) {
|
|
251
|
+
context = {};
|
|
252
|
+
}
|
|
253
|
+
var tag = container.nodeName.toLowerCase();
|
|
254
|
+
context[validateDOMNesting.ancestorInfoContextKey] = validateDOMNesting.updatedAncestorInfo(null, tag, null);
|
|
255
|
+
}
|
|
256
|
+
var markup = ReactReconciler.mountComponent(componentInstance, rootID, transaction, context);
|
|
257
|
+
componentInstance._renderedComponent._topLevelWrapper = componentInstance;
|
|
252
258
|
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
253
259
|
}
|
|
254
260
|
|
|
@@ -260,24 +266,45 @@ function mountComponentIntoNode(
|
|
|
260
266
|
* @param {DOMElement} container DOM element to mount into.
|
|
261
267
|
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
262
268
|
*/
|
|
263
|
-
function batchedMountComponentIntoNode(
|
|
264
|
-
componentInstance,
|
|
265
|
-
rootID,
|
|
266
|
-
container,
|
|
267
|
-
shouldReuseMarkup) {
|
|
269
|
+
function batchedMountComponentIntoNode(componentInstance, rootID, container, shouldReuseMarkup, context) {
|
|
268
270
|
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
269
|
-
transaction.perform(
|
|
270
|
-
mountComponentIntoNode,
|
|
271
|
-
null,
|
|
272
|
-
componentInstance,
|
|
273
|
-
rootID,
|
|
274
|
-
container,
|
|
275
|
-
transaction,
|
|
276
|
-
shouldReuseMarkup
|
|
277
|
-
);
|
|
271
|
+
transaction.perform(mountComponentIntoNode, null, componentInstance, rootID, container, transaction, shouldReuseMarkup, context);
|
|
278
272
|
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
279
273
|
}
|
|
280
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Unmounts a component and removes it from the DOM.
|
|
277
|
+
*
|
|
278
|
+
* @param {ReactComponent} instance React component instance.
|
|
279
|
+
* @param {DOMElement} container DOM element to unmount from.
|
|
280
|
+
* @final
|
|
281
|
+
* @internal
|
|
282
|
+
* @see {ReactMount.unmountComponentAtNode}
|
|
283
|
+
*/
|
|
284
|
+
function unmountComponentFromNode(instance, container) {
|
|
285
|
+
ReactReconciler.unmountComponent(instance);
|
|
286
|
+
|
|
287
|
+
if (container.nodeType === DOC_NODE_TYPE) {
|
|
288
|
+
container = container.documentElement;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// http://jsperf.com/emptying-a-node
|
|
292
|
+
while (container.lastChild) {
|
|
293
|
+
container.removeChild(container.lastChild);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Temporary (?) hack so that we can store all top-level pending updates on
|
|
299
|
+
* composites instead of having to worry about different types of components
|
|
300
|
+
* here.
|
|
301
|
+
*/
|
|
302
|
+
var TopLevelWrapper = function () {};
|
|
303
|
+
TopLevelWrapper.prototype.render = function () {
|
|
304
|
+
// this.props is actually a ReactElement
|
|
305
|
+
return this.props;
|
|
306
|
+
};
|
|
307
|
+
|
|
281
308
|
/**
|
|
282
309
|
* Mounting is the process of initializing a React component by creating its
|
|
283
310
|
* representative DOM elements and inserting them into a supplied `container`.
|
|
@@ -308,7 +335,7 @@ var ReactMount = {
|
|
|
308
335
|
* @param {DOMElement} container The `container` being rendered into.
|
|
309
336
|
* @param {function} renderCallback This must be called once to do the render.
|
|
310
337
|
*/
|
|
311
|
-
scrollMonitor: function(container, renderCallback) {
|
|
338
|
+
scrollMonitor: function (container, renderCallback) {
|
|
312
339
|
renderCallback();
|
|
313
340
|
},
|
|
314
341
|
|
|
@@ -319,26 +346,17 @@ var ReactMount = {
|
|
|
319
346
|
* @param {DOMElement} container container to render into
|
|
320
347
|
* @param {?function} callback function triggered on completion
|
|
321
348
|
*/
|
|
322
|
-
_updateRootComponent: function(
|
|
323
|
-
|
|
324
|
-
nextElement,
|
|
325
|
-
container,
|
|
326
|
-
callback) {
|
|
327
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
328
|
-
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
ReactMount.scrollMonitor(container, function() {
|
|
349
|
+
_updateRootComponent: function (prevComponent, nextElement, container, callback) {
|
|
350
|
+
ReactMount.scrollMonitor(container, function () {
|
|
332
351
|
ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement);
|
|
333
352
|
if (callback) {
|
|
334
353
|
ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
|
|
335
354
|
}
|
|
336
355
|
});
|
|
337
356
|
|
|
338
|
-
if (
|
|
357
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
339
358
|
// Record the root element in case it later gets transplanted.
|
|
340
|
-
rootElementsByReactRootID[getReactRootID(container)] =
|
|
341
|
-
getReactRootElementInContainer(container);
|
|
359
|
+
rootElementsByReactRootID[getReactRootID(container)] = getReactRootElementInContainer(container);
|
|
342
360
|
}
|
|
343
361
|
|
|
344
362
|
return prevComponent;
|
|
@@ -351,15 +369,8 @@ var ReactMount = {
|
|
|
351
369
|
* @param {DOMElement} container container to render into
|
|
352
370
|
* @return {string} reactRoot ID prefix
|
|
353
371
|
*/
|
|
354
|
-
_registerComponent: function(nextComponent, container) {
|
|
355
|
-
(
|
|
356
|
-
container && (
|
|
357
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
358
|
-
),
|
|
359
|
-
'_registerComponent(...): Target container is not a DOM element.'
|
|
360
|
-
) : invariant(container && (
|
|
361
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
362
|
-
)));
|
|
372
|
+
_registerComponent: function (nextComponent, container) {
|
|
373
|
+
!(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? 'production' !== process.env.NODE_ENV ? invariant(false, '_registerComponent(...): Target container is not a DOM element.') : invariant(false) : undefined;
|
|
363
374
|
|
|
364
375
|
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
|
|
365
376
|
|
|
@@ -375,44 +386,24 @@ var ReactMount = {
|
|
|
375
386
|
* @param {boolean} shouldReuseMarkup if we should skip the markup insertion
|
|
376
387
|
* @return {ReactComponent} nextComponent
|
|
377
388
|
*/
|
|
378
|
-
_renderNewRootComponent: function(
|
|
379
|
-
nextElement,
|
|
380
|
-
container,
|
|
381
|
-
shouldReuseMarkup
|
|
382
|
-
) {
|
|
389
|
+
_renderNewRootComponent: function (nextElement, container, shouldReuseMarkup, context) {
|
|
383
390
|
// Various parts of our code (such as ReactCompositeComponent's
|
|
384
391
|
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
385
392
|
// verify that that's the case.
|
|
386
|
-
|
|
387
|
-
ReactCurrentOwner.current == null,
|
|
388
|
-
'_renderNewRootComponent(): Render methods should be a pure function ' +
|
|
389
|
-
'of props and state; triggering nested component updates from ' +
|
|
390
|
-
'render is not allowed. If necessary, trigger nested updates in ' +
|
|
391
|
-
'componentDidUpdate.'
|
|
392
|
-
) : null);
|
|
393
|
+
'production' !== process.env.NODE_ENV ? warning(ReactCurrentOwner.current == null, '_renderNewRootComponent(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : undefined;
|
|
393
394
|
|
|
394
395
|
var componentInstance = instantiateReactComponent(nextElement, null);
|
|
395
|
-
var reactRootID = ReactMount._registerComponent(
|
|
396
|
-
componentInstance,
|
|
397
|
-
container
|
|
398
|
-
);
|
|
396
|
+
var reactRootID = ReactMount._registerComponent(componentInstance, container);
|
|
399
397
|
|
|
400
398
|
// The initial render is synchronous but any updates that happen during
|
|
401
399
|
// rendering, in componentWillMount or componentDidMount, will be batched
|
|
402
400
|
// according to the current batching strategy.
|
|
403
401
|
|
|
404
|
-
ReactUpdates.batchedUpdates(
|
|
405
|
-
batchedMountComponentIntoNode,
|
|
406
|
-
componentInstance,
|
|
407
|
-
reactRootID,
|
|
408
|
-
container,
|
|
409
|
-
shouldReuseMarkup
|
|
410
|
-
);
|
|
402
|
+
ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, reactRootID, container, shouldReuseMarkup, context);
|
|
411
403
|
|
|
412
|
-
if (
|
|
404
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
413
405
|
// Record the root element in case it later gets transplanted.
|
|
414
|
-
rootElementsByReactRootID[reactRootID] =
|
|
415
|
-
getReactRootElementInContainer(container);
|
|
406
|
+
rootElementsByReactRootID[reactRootID] = getReactRootElementInContainer(container);
|
|
416
407
|
}
|
|
417
408
|
|
|
418
409
|
return componentInstance;
|
|
@@ -425,61 +416,47 @@ var ReactMount = {
|
|
|
425
416
|
* perform an update on it and only mutate the DOM as necessary to reflect the
|
|
426
417
|
* latest React component.
|
|
427
418
|
*
|
|
419
|
+
* @param {ReactComponent} parentComponent The conceptual parent of this render tree.
|
|
428
420
|
* @param {ReactElement} nextElement Component element to render.
|
|
429
421
|
* @param {DOMElement} container DOM element to render into.
|
|
430
422
|
* @param {?function} callback function triggered on completion
|
|
431
423
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
432
424
|
*/
|
|
433
|
-
|
|
434
|
-
(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
' This may be caused by unintentionally loading two independent ' +
|
|
447
|
-
'copies of React.' :
|
|
448
|
-
''
|
|
449
|
-
)
|
|
450
|
-
) : invariant(ReactElement.isValidElement(nextElement)));
|
|
425
|
+
renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
|
426
|
+
!(parentComponent != null && parentComponent._reactInternalInstance != null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'parentComponent must be a valid React Component') : invariant(false) : undefined;
|
|
427
|
+
return ReactMount._renderSubtreeIntoContainer(parentComponent, nextElement, container, callback);
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
_renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
|
431
|
+
!ReactElement.isValidElement(nextElement) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'React.render(): Invalid component element.%s', typeof nextElement === 'string' ? ' Instead of passing an element string, make sure to instantiate ' + 'it by passing it to React.createElement.' : typeof nextElement === 'function' ? ' Instead of passing a component class, make sure to instantiate ' + 'it by passing it to React.createElement.' :
|
|
432
|
+
// Check if it quacks like an element
|
|
433
|
+
nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : invariant(false) : undefined;
|
|
434
|
+
|
|
435
|
+
'production' !== process.env.NODE_ENV ? warning(!container || !container.tagName || container.tagName.toUpperCase() !== 'BODY', 'render(): Rendering components directly into document.body is ' + 'discouraged, since its children are often manipulated by third-party ' + 'scripts and browser extensions. This may lead to subtle ' + 'reconciliation issues. Try rendering into a container element created ' + 'for your app.') : undefined;
|
|
436
|
+
|
|
437
|
+
var nextWrappedElement = new ReactElement(TopLevelWrapper, null, null, null, nextElement);
|
|
451
438
|
|
|
452
439
|
var prevComponent = instancesByReactRootID[getReactRootID(container)];
|
|
453
440
|
|
|
454
441
|
if (prevComponent) {
|
|
455
|
-
var
|
|
442
|
+
var prevWrappedElement = prevComponent._currentElement;
|
|
443
|
+
var prevElement = prevWrappedElement.props;
|
|
456
444
|
if (shouldUpdateReactComponent(prevElement, nextElement)) {
|
|
457
|
-
return ReactMount._updateRootComponent(
|
|
458
|
-
prevComponent,
|
|
459
|
-
nextElement,
|
|
460
|
-
container,
|
|
461
|
-
callback
|
|
462
|
-
).getPublicInstance();
|
|
445
|
+
return ReactMount._updateRootComponent(prevComponent, nextWrappedElement, container, callback)._renderedComponent.getPublicInstance();
|
|
463
446
|
} else {
|
|
464
447
|
ReactMount.unmountComponentAtNode(container);
|
|
465
448
|
}
|
|
466
449
|
}
|
|
467
450
|
|
|
468
451
|
var reactRootElement = getReactRootElementInContainer(container);
|
|
469
|
-
var containerHasReactMarkup =
|
|
470
|
-
reactRootElement && ReactMount.isRenderedByReact(reactRootElement);
|
|
452
|
+
var containerHasReactMarkup = reactRootElement && ReactMount.isRenderedByReact(reactRootElement);
|
|
471
453
|
|
|
472
|
-
if (
|
|
454
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
473
455
|
if (!containerHasReactMarkup || reactRootElement.nextSibling) {
|
|
474
456
|
var rootElementSibling = reactRootElement;
|
|
475
457
|
while (rootElementSibling) {
|
|
476
458
|
if (ReactMount.isRenderedByReact(rootElementSibling)) {
|
|
477
|
-
|
|
478
|
-
false,
|
|
479
|
-
'render(): Target node has markup rendered by React, but there ' +
|
|
480
|
-
'are unrelated nodes as well. This is most commonly caused by ' +
|
|
481
|
-
'white-space inserted around server-rendered markup.'
|
|
482
|
-
) : null);
|
|
459
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'render(): Target node has markup rendered by React, but there ' + 'are unrelated nodes as well. This is most commonly caused by ' + 'white-space inserted around server-rendered markup.') : undefined;
|
|
483
460
|
break;
|
|
484
461
|
}
|
|
485
462
|
|
|
@@ -489,12 +466,7 @@ var ReactMount = {
|
|
|
489
466
|
}
|
|
490
467
|
|
|
491
468
|
var shouldReuseMarkup = containerHasReactMarkup && !prevComponent;
|
|
492
|
-
|
|
493
|
-
var component = ReactMount._renderNewRootComponent(
|
|
494
|
-
nextElement,
|
|
495
|
-
container,
|
|
496
|
-
shouldReuseMarkup
|
|
497
|
-
).getPublicInstance();
|
|
469
|
+
var component = ReactMount._renderNewRootComponent(nextWrappedElement, container, shouldReuseMarkup, parentComponent != null ? parentComponent._reactInternalInstance._processChildContext(parentComponent._reactInternalInstance._context) : emptyObject)._renderedComponent.getPublicInstance();
|
|
498
470
|
if (callback) {
|
|
499
471
|
callback.call(component);
|
|
500
472
|
}
|
|
@@ -502,36 +474,19 @@ var ReactMount = {
|
|
|
502
474
|
},
|
|
503
475
|
|
|
504
476
|
/**
|
|
505
|
-
*
|
|
506
|
-
*
|
|
477
|
+
* Renders a React component into the DOM in the supplied `container`.
|
|
478
|
+
*
|
|
479
|
+
* If the React component was previously rendered into `container`, this will
|
|
480
|
+
* perform an update on it and only mutate the DOM as necessary to reflect the
|
|
481
|
+
* latest React component.
|
|
507
482
|
*
|
|
508
|
-
* @param {
|
|
509
|
-
* @param {?object} props Initial props of the component instance.
|
|
483
|
+
* @param {ReactElement} nextElement Component element to render.
|
|
510
484
|
* @param {DOMElement} container DOM element to render into.
|
|
485
|
+
* @param {?function} callback function triggered on completion
|
|
511
486
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
512
487
|
*/
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
return ReactMount.render(element, container);
|
|
516
|
-
},
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Constructs a component instance of `constructor` with `initialProps` and
|
|
520
|
-
* renders it into a container node identified by supplied `id`.
|
|
521
|
-
*
|
|
522
|
-
* @param {function} componentConstructor React component constructor
|
|
523
|
-
* @param {?object} props Initial props of the component instance.
|
|
524
|
-
* @param {string} id ID of the DOM element to render into.
|
|
525
|
-
* @return {ReactComponent} Component instance rendered in the container node.
|
|
526
|
-
*/
|
|
527
|
-
constructAndRenderComponentByID: function(constructor, props, id) {
|
|
528
|
-
var domNode = document.getElementById(id);
|
|
529
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
530
|
-
domNode,
|
|
531
|
-
'Tried to get element with id of "%s" but it is not present on the page.',
|
|
532
|
-
id
|
|
533
|
-
) : invariant(domNode));
|
|
534
|
-
return ReactMount.constructAndRenderComponent(constructor, props, domNode);
|
|
488
|
+
render: function (nextElement, container, callback) {
|
|
489
|
+
return ReactMount._renderSubtreeIntoContainer(null, nextElement, container, callback);
|
|
535
490
|
},
|
|
536
491
|
|
|
537
492
|
/**
|
|
@@ -542,7 +497,7 @@ var ReactMount = {
|
|
|
542
497
|
* @param {DOMElement} container DOM element to register as a container.
|
|
543
498
|
* @return {string} The "reactRoot" ID of elements rendered within.
|
|
544
499
|
*/
|
|
545
|
-
registerContainer: function(container) {
|
|
500
|
+
registerContainer: function (container) {
|
|
546
501
|
var reactRootID = getReactRootID(container);
|
|
547
502
|
if (reactRootID) {
|
|
548
503
|
// If one exists, make sure it is a valid "reactRoot" ID.
|
|
@@ -563,64 +518,29 @@ var ReactMount = {
|
|
|
563
518
|
* @return {boolean} True if a component was found in and unmounted from
|
|
564
519
|
* `container`
|
|
565
520
|
*/
|
|
566
|
-
unmountComponentAtNode: function(container) {
|
|
521
|
+
unmountComponentAtNode: function (container) {
|
|
567
522
|
// Various parts of our code (such as ReactCompositeComponent's
|
|
568
523
|
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
569
524
|
// verify that that's the case. (Strictly speaking, unmounting won't cause a
|
|
570
525
|
// render but we still don't expect to be in a render call here.)
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
'props and state; triggering nested component updates from render is ' +
|
|
575
|
-
'not allowed. If necessary, trigger nested updates in ' +
|
|
576
|
-
'componentDidUpdate.'
|
|
577
|
-
) : null);
|
|
578
|
-
|
|
579
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
580
|
-
container && (
|
|
581
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
582
|
-
),
|
|
583
|
-
'unmountComponentAtNode(...): Target container is not a DOM element.'
|
|
584
|
-
) : invariant(container && (
|
|
585
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
586
|
-
)));
|
|
526
|
+
'production' !== process.env.NODE_ENV ? warning(ReactCurrentOwner.current == null, 'unmountComponentAtNode(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from render ' + 'is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : undefined;
|
|
527
|
+
|
|
528
|
+
!(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'unmountComponentAtNode(...): Target container is not a DOM element.') : invariant(false) : undefined;
|
|
587
529
|
|
|
588
530
|
var reactRootID = getReactRootID(container);
|
|
589
531
|
var component = instancesByReactRootID[reactRootID];
|
|
590
532
|
if (!component) {
|
|
591
533
|
return false;
|
|
592
534
|
}
|
|
593
|
-
|
|
535
|
+
ReactUpdates.batchedUpdates(unmountComponentFromNode, component, container);
|
|
594
536
|
delete instancesByReactRootID[reactRootID];
|
|
595
537
|
delete containersByReactRootID[reactRootID];
|
|
596
|
-
if (
|
|
538
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
597
539
|
delete rootElementsByReactRootID[reactRootID];
|
|
598
540
|
}
|
|
599
541
|
return true;
|
|
600
542
|
},
|
|
601
543
|
|
|
602
|
-
/**
|
|
603
|
-
* Unmounts a component and removes it from the DOM.
|
|
604
|
-
*
|
|
605
|
-
* @param {ReactComponent} instance React component instance.
|
|
606
|
-
* @param {DOMElement} container DOM element to unmount from.
|
|
607
|
-
* @final
|
|
608
|
-
* @internal
|
|
609
|
-
* @see {ReactMount.unmountComponentAtNode}
|
|
610
|
-
*/
|
|
611
|
-
unmountComponentFromNode: function(instance, container) {
|
|
612
|
-
ReactReconciler.unmountComponent(instance);
|
|
613
|
-
|
|
614
|
-
if (container.nodeType === DOC_NODE_TYPE) {
|
|
615
|
-
container = container.documentElement;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// http://jsperf.com/emptying-a-node
|
|
619
|
-
while (container.lastChild) {
|
|
620
|
-
container.removeChild(container.lastChild);
|
|
621
|
-
}
|
|
622
|
-
},
|
|
623
|
-
|
|
624
544
|
/**
|
|
625
545
|
* Finds the container DOM element that contains React component to which the
|
|
626
546
|
* supplied DOM `id` belongs.
|
|
@@ -628,36 +548,26 @@ var ReactMount = {
|
|
|
628
548
|
* @param {string} id The ID of an element rendered by a React component.
|
|
629
549
|
* @return {?DOMElement} DOM element that contains the `id`.
|
|
630
550
|
*/
|
|
631
|
-
findReactContainerForID: function(id) {
|
|
551
|
+
findReactContainerForID: function (id) {
|
|
632
552
|
var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(id);
|
|
633
553
|
var container = containersByReactRootID[reactRootID];
|
|
634
554
|
|
|
635
|
-
if (
|
|
555
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
636
556
|
var rootElement = rootElementsByReactRootID[reactRootID];
|
|
637
557
|
if (rootElement && rootElement.parentNode !== container) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
// findReactContainerForID (this function).
|
|
641
|
-
internalGetID(rootElement) === reactRootID,
|
|
642
|
-
'ReactMount: Root element ID differed from reactRootID.'
|
|
643
|
-
) : invariant(// Call internalGetID here because getID calls isValid which calls
|
|
558
|
+
'production' !== process.env.NODE_ENV ? warning(
|
|
559
|
+
// Call internalGetID here because getID calls isValid which calls
|
|
644
560
|
// findReactContainerForID (this function).
|
|
645
|
-
internalGetID(rootElement) === reactRootID)
|
|
646
|
-
|
|
561
|
+
internalGetID(rootElement) === reactRootID, 'ReactMount: Root element ID differed from reactRootID.') : undefined;
|
|
647
562
|
var containerChild = container.firstChild;
|
|
648
|
-
if (containerChild &&
|
|
649
|
-
reactRootID === internalGetID(containerChild)) {
|
|
563
|
+
if (containerChild && reactRootID === internalGetID(containerChild)) {
|
|
650
564
|
// If the container has a new child with the same ID as the old
|
|
651
565
|
// root element, then rootElementsByReactRootID[reactRootID] is
|
|
652
566
|
// just stale and needs to be updated. The case that deserves a
|
|
653
567
|
// warning is when the container is empty.
|
|
654
568
|
rootElementsByReactRootID[reactRootID] = containerChild;
|
|
655
569
|
} else {
|
|
656
|
-
|
|
657
|
-
false,
|
|
658
|
-
'ReactMount: Root element has been removed from its original ' +
|
|
659
|
-
'container. New container:', rootElement.parentNode
|
|
660
|
-
) : null);
|
|
570
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'ReactMount: Root element has been removed from its original ' + 'container. New container: %s', rootElement.parentNode) : undefined;
|
|
661
571
|
}
|
|
662
572
|
}
|
|
663
573
|
}
|
|
@@ -671,7 +581,7 @@ var ReactMount = {
|
|
|
671
581
|
* @param {string} id ID of a DOM node in the React component.
|
|
672
582
|
* @return {DOMElement} Root DOM node of the React component.
|
|
673
583
|
*/
|
|
674
|
-
findReactNodeByID: function(id) {
|
|
584
|
+
findReactNodeByID: function (id) {
|
|
675
585
|
var reactRoot = ReactMount.findReactContainerForID(id);
|
|
676
586
|
return ReactMount.findComponentRoot(reactRoot, id);
|
|
677
587
|
},
|
|
@@ -683,7 +593,7 @@ var ReactMount = {
|
|
|
683
593
|
* @return {boolean} True if the DOM Element appears to be rendered by React.
|
|
684
594
|
* @internal
|
|
685
595
|
*/
|
|
686
|
-
isRenderedByReact: function(node) {
|
|
596
|
+
isRenderedByReact: function (node) {
|
|
687
597
|
if (node.nodeType !== 1) {
|
|
688
598
|
// Not a DOMElement, therefore not a React component
|
|
689
599
|
return false;
|
|
@@ -700,7 +610,7 @@ var ReactMount = {
|
|
|
700
610
|
* @return {?DOMEventTarget}
|
|
701
611
|
* @internal
|
|
702
612
|
*/
|
|
703
|
-
getFirstReactDOM: function(node) {
|
|
613
|
+
getFirstReactDOM: function (node) {
|
|
704
614
|
var current = node;
|
|
705
615
|
while (current && current.parentNode !== current) {
|
|
706
616
|
if (ReactMount.isRenderedByReact(current)) {
|
|
@@ -721,7 +631,7 @@ var ReactMount = {
|
|
|
721
631
|
* @return {DOMEventTarget} DOM node with the supplied `targetID`.
|
|
722
632
|
* @internal
|
|
723
633
|
*/
|
|
724
|
-
findComponentRoot: function(ancestorNode, targetID) {
|
|
634
|
+
findComponentRoot: function (ancestorNode, targetID) {
|
|
725
635
|
var firstChildren = findComponentRootReusableArray;
|
|
726
636
|
var childIndex = 0;
|
|
727
637
|
|
|
@@ -752,7 +662,6 @@ var ReactMount = {
|
|
|
752
662
|
firstChildren.length = childIndex = 0;
|
|
753
663
|
firstChildren.push(child.firstChild);
|
|
754
664
|
}
|
|
755
|
-
|
|
756
665
|
} else {
|
|
757
666
|
// If this child had no ID, then there's a chance that it was
|
|
758
667
|
// injected automatically by the browser, as when a `<table>`
|
|
@@ -777,87 +686,35 @@ var ReactMount = {
|
|
|
777
686
|
|
|
778
687
|
firstChildren.length = 0;
|
|
779
688
|
|
|
780
|
-
|
|
781
|
-
false,
|
|
782
|
-
'findComponentRoot(..., %s): Unable to find element. This probably ' +
|
|
783
|
-
'means the DOM was unexpectedly mutated (e.g., by the browser), ' +
|
|
784
|
-
'usually due to forgetting a <tbody> when using tables, nesting tags ' +
|
|
785
|
-
'like <form>, <p>, or <a>, or using non-SVG elements in an <svg> ' +
|
|
786
|
-
'parent. ' +
|
|
787
|
-
'Try inspecting the child nodes of the element with React ID `%s`.',
|
|
788
|
-
targetID,
|
|
789
|
-
ReactMount.getID(ancestorNode)
|
|
790
|
-
) : invariant(false));
|
|
689
|
+
!false ? 'production' !== process.env.NODE_ENV ? invariant(false, 'findComponentRoot(..., %s): Unable to find element. This probably ' + 'means the DOM was unexpectedly mutated (e.g., by the browser), ' + 'usually due to forgetting a <tbody> when using tables, nesting tags ' + 'like <form>, <p>, or <a>, or using non-SVG elements in an <svg> ' + 'parent. ' + 'Try inspecting the child nodes of the element with React ID `%s`.', targetID, ReactMount.getID(ancestorNode)) : invariant(false) : undefined;
|
|
791
690
|
},
|
|
792
691
|
|
|
793
|
-
_mountImageIntoNode: function(markup, container, shouldReuseMarkup) {
|
|
794
|
-
(
|
|
795
|
-
container && (
|
|
796
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
797
|
-
),
|
|
798
|
-
'mountComponentIntoNode(...): Target container is not valid.'
|
|
799
|
-
) : invariant(container && (
|
|
800
|
-
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
|
|
801
|
-
)));
|
|
692
|
+
_mountImageIntoNode: function (markup, container, shouldReuseMarkup) {
|
|
693
|
+
!(container && (container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE || container.nodeType === DOCUMENT_FRAGMENT_NODE_TYPE)) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'mountComponentIntoNode(...): Target container is not valid.') : invariant(false) : undefined;
|
|
802
694
|
|
|
803
695
|
if (shouldReuseMarkup) {
|
|
804
696
|
var rootElement = getReactRootElementInContainer(container);
|
|
805
697
|
if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
|
|
806
698
|
return;
|
|
807
699
|
} else {
|
|
808
|
-
var checksum = rootElement.getAttribute(
|
|
809
|
-
ReactMarkupChecksum.CHECKSUM_ATTR_NAME
|
|
810
|
-
);
|
|
700
|
+
var checksum = rootElement.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
811
701
|
rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
812
702
|
|
|
813
703
|
var rootMarkup = rootElement.outerHTML;
|
|
814
|
-
rootElement.setAttribute(
|
|
815
|
-
ReactMarkupChecksum.CHECKSUM_ATTR_NAME,
|
|
816
|
-
checksum
|
|
817
|
-
);
|
|
704
|
+
rootElement.setAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME, checksum);
|
|
818
705
|
|
|
819
706
|
var diffIndex = firstDifferenceIndex(markup, rootMarkup);
|
|
820
|
-
var difference = ' (client) ' +
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
(
|
|
825
|
-
container.
|
|
826
|
-
'You\'re trying to render a component to the document using ' +
|
|
827
|
-
'server rendering but the checksum was invalid. This usually ' +
|
|
828
|
-
'means you rendered a different component type or props on ' +
|
|
829
|
-
'the client from the one on the server, or your render() ' +
|
|
830
|
-
'methods are impure. React cannot handle this case due to ' +
|
|
831
|
-
'cross-browser quirks by rendering at the document root. You ' +
|
|
832
|
-
'should look for environment dependent code in your components ' +
|
|
833
|
-
'and ensure the props are the same client and server side:\n%s',
|
|
834
|
-
difference
|
|
835
|
-
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
836
|
-
|
|
837
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
838
|
-
("production" !== process.env.NODE_ENV ? warning(
|
|
839
|
-
false,
|
|
840
|
-
'React attempted to reuse markup in a container but the ' +
|
|
841
|
-
'checksum was invalid. This generally means that you are ' +
|
|
842
|
-
'using server rendering and the markup generated on the ' +
|
|
843
|
-
'server was not what the client was expecting. React injected ' +
|
|
844
|
-
'new markup to compensate which works but you have lost many ' +
|
|
845
|
-
'of the benefits of server rendering. Instead, figure out ' +
|
|
846
|
-
'why the markup being generated is different on the client ' +
|
|
847
|
-
'or server:\n%s',
|
|
848
|
-
difference
|
|
849
|
-
) : null);
|
|
707
|
+
var difference = ' (client) ' + markup.substring(diffIndex - 20, diffIndex + 20) + '\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
|
|
708
|
+
|
|
709
|
+
!(container.nodeType !== DOC_NODE_TYPE) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'You\'re trying to render a component to the document using ' + 'server rendering but the checksum was invalid. This usually ' + 'means you rendered a different component type or props on ' + 'the client from the one on the server, or your render() ' + 'methods are impure. React cannot handle this case due to ' + 'cross-browser quirks by rendering at the document root. You ' + 'should look for environment dependent code in your components ' + 'and ensure the props are the same client and server side:\n%s', difference) : invariant(false) : undefined;
|
|
710
|
+
|
|
711
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
712
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'React attempted to reuse markup in a container but the ' + 'checksum was invalid. This generally means that you are ' + 'using server rendering and the markup generated on the ' + 'server was not what the client was expecting. React injected ' + 'new markup to compensate which works but you have lost many ' + 'of the benefits of server rendering. Instead, figure out ' + 'why the markup being generated is different on the client ' + 'or server:\n%s', difference) : undefined;
|
|
850
713
|
}
|
|
851
714
|
}
|
|
852
715
|
}
|
|
853
716
|
|
|
854
|
-
(
|
|
855
|
-
container.nodeType !== DOC_NODE_TYPE,
|
|
856
|
-
'You\'re trying to render a component to the document but ' +
|
|
857
|
-
'you didn\'t use server rendering. We can\'t do this ' +
|
|
858
|
-
'without using server rendering due to cross-browser quirks. ' +
|
|
859
|
-
'See React.renderToString() for server rendering.'
|
|
860
|
-
) : invariant(container.nodeType !== DOC_NODE_TYPE));
|
|
717
|
+
!(container.nodeType !== DOC_NODE_TYPE) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'You\'re trying to render a component to the document but ' + 'you didn\'t use server rendering. We can\'t do this ' + 'without using server rendering due to cross-browser quirks. ' + 'See React.renderToString() for server rendering.') : invariant(false) : undefined;
|
|
861
718
|
|
|
862
719
|
setInnerHTML(container, markup);
|
|
863
720
|
},
|
|
@@ -884,4 +741,4 @@ ReactPerf.measureMethods(ReactMount, 'ReactMount', {
|
|
|
884
741
|
_mountImageIntoNode: '_mountImageIntoNode'
|
|
885
742
|
});
|
|
886
743
|
|
|
887
|
-
module.exports = ReactMount;
|
|
744
|
+
module.exports = ReactMount;
|