react 0.13.2 → 0.14.0-alpha3
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 +1 -1
- package/addons.js +7 -0
- package/addons/CSSTransitionGroup.js +1 -0
- package/addons/LinkedStateMixin.js +1 -0
- package/addons/Perf.js +1 -0
- package/addons/PureRenderMixin.js +1 -0
- package/addons/TestUtils.js +1 -0
- package/addons/TransitionGroup.js +1 -0
- package/addons/batchedUpdates.js +1 -0
- package/addons/cloneWithProps.js +1 -0
- package/addons/createFragment.js +1 -0
- package/addons/renderSubtreeIntoContainer.js +1 -0
- package/addons/shallowCompare.js +1 -0
- package/addons/update.js +1 -0
- package/dist/JSXTransformer.js +3355 -1685
- package/dist/react-with-addons.js +3320 -5133
- package/dist/react-with-addons.min.js +6 -7
- package/dist/react.js +2962 -4548
- package/dist/react.min.js +5 -5
- package/lib/AutoFocusMixin.js +4 -3
- 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 +24 -88
- package/lib/ClientReactRootIndex.js +2 -2
- package/lib/DOMChildrenOperations.js +13 -33
- package/lib/DOMProperty.js +41 -67
- package/lib/DOMPropertyOperations.js +30 -51
- 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 +27 -38
- package/lib/EventPropagators.js +23 -26
- package/lib/ExecutionEnvironment.js +4 -8
- package/lib/FallbackCompositionState.js +3 -3
- package/lib/HTMLDOMPropertyConfig.js +7 -19
- package/lib/LinkedStateMixin.js +3 -6
- package/lib/LinkedValueUtils.js +34 -64
- package/lib/LocalEventTrapMixin.js +9 -16
- package/lib/Object.assign.js +1 -1
- package/lib/PooledClass.js +8 -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 +18 -28
- package/lib/ReactChildReconciler.js +11 -19
- package/lib/ReactChildren.js +21 -28
- package/lib/ReactClass.js +81 -234
- package/lib/ReactComponent.js +17 -33
- package/lib/ReactComponentBrowserEnvironment.js +4 -8
- package/lib/ReactComponentEnvironment.js +6 -12
- package/lib/ReactComponentWithPureRenderMixin.js +4 -5
- package/lib/ReactCompositeComponent.js +87 -311
- package/lib/ReactContext.js +2 -44
- package/lib/ReactCurrentOwner.js +1 -3
- package/lib/ReactDOM.js +4 -2
- package/lib/ReactDOMButton.js +3 -4
- package/lib/ReactDOMClient.js +85 -0
- package/lib/ReactDOMComponent.js +182 -146
- package/lib/ReactDOMForm.js +3 -3
- package/lib/ReactDOMIDOperations.js +11 -22
- package/lib/ReactDOMIframe.js +3 -3
- package/lib/ReactDOMImg.js +3 -3
- package/lib/ReactDOMInput.js +22 -35
- package/lib/ReactDOMOption.js +67 -10
- package/lib/ReactDOMSelect.js +50 -28
- package/lib/ReactDOMSelection.js +5 -20
- package/lib/ReactDOMServer.js +24 -0
- package/lib/ReactDOMTextComponent.js +17 -18
- package/lib/ReactDOMTextarea.js +15 -27
- package/lib/ReactDefaultBatchingStrategy.js +9 -13
- package/lib/ReactDefaultInjection.js +31 -40
- package/lib/ReactDefaultPerf.js +36 -69
- package/lib/ReactDefaultPerfAnalysis.js +8 -14
- package/lib/ReactElement.js +24 -57
- package/lib/ReactElementValidator.js +38 -105
- package/lib/ReactEmptyComponent.js +7 -11
- package/lib/ReactErrorUtils.js +2 -2
- package/lib/ReactEventEmitterMixin.js +3 -12
- package/lib/ReactEventListener.js +16 -38
- package/lib/ReactFragment.js +23 -54
- package/lib/ReactInjection.js +1 -1
- package/lib/ReactInputSelection.js +11 -21
- package/lib/ReactInstanceHandles.js +27 -57
- package/lib/ReactInstanceMap.js +5 -5
- package/lib/ReactIsomorphic.js +70 -0
- package/lib/ReactLifeCycle.js +1 -1
- package/lib/ReactLink.js +2 -4
- package/lib/ReactMarkupChecksum.js +5 -10
- package/lib/ReactMount.js +137 -260
- package/lib/ReactMultiChild.js +19 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +7 -11
- 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 +9 -34
- package/lib/ReactReconciler.js +9 -19
- package/lib/ReactRef.js +5 -8
- package/lib/ReactRootIndex.js +2 -2
- package/lib/ReactServerRendering.js +7 -15
- package/lib/ReactServerRenderingTransaction.js +7 -32
- package/lib/ReactStateSetters.js +6 -6
- package/lib/ReactTestUtils.js +93 -165
- package/lib/ReactTransitionChildMapping.js +5 -7
- package/lib/ReactTransitionEvents.js +5 -5
- package/lib/ReactTransitionGroup.js +30 -52
- package/lib/ReactUpdateQueue.js +27 -90
- package/lib/ReactUpdates.js +27 -79
- package/lib/ReactWithAddons.js +7 -6
- package/lib/SVGDOMPropertyConfig.js +41 -4
- package/lib/SelectEventPlugin.js +28 -29
- package/lib/ServerReactRootIndex.js +2 -2
- package/lib/SimpleEventPlugin.js +136 -128
- package/lib/SyntheticClipboardEvent.js +3 -7
- package/lib/SyntheticCompositionEvent.js +3 -9
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +8 -10
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +3 -9
- package/lib/SyntheticKeyboardEvent.js +4 -4
- package/lib/SyntheticMouseEvent.js +8 -14
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +3 -3
- package/lib/SyntheticWheelEvent.js +11 -15
- package/lib/Transaction.js +12 -24
- 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 +5 -11
- package/lib/containsNode.js +29 -16
- package/lib/createArrayFromMixed.js +17 -16
- package/lib/createFullPageComponent.js +4 -11
- package/lib/createNodesFromMarkup.js +6 -8
- package/lib/dangerousStyleValue.js +2 -3
- package/lib/emptyFunction.js +10 -4
- package/lib/emptyObject.js +1 -1
- package/lib/escapeTextContentForBrowser.js +1 -1
- package/lib/findDOMNode.js +5 -24
- package/lib/flattenChildren.js +4 -10
- package/lib/focusNode.js +2 -3
- package/lib/forEachAccumulated.js +2 -2
- package/lib/getActiveElement.js +4 -2
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +2 -4
- package/lib/getMarkupWrap.js +7 -5
- 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 +14 -38
- package/lib/invariant.js +8 -12
- package/lib/isEventSupported.js +7 -10
- package/lib/isNode.js +4 -6
- package/lib/isTextInputElement.js +2 -4
- package/lib/isTextNode.js +3 -1
- package/lib/joinClasses.js +2 -2
- 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 +22 -89
- package/lib/update.js +25 -85
- package/lib/validateDOMNesting.js +363 -0
- package/lib/warning.js +17 -15
- package/package.json +3 -3
- package/lib/MobileSafariClickEventPlugin.js +0 -56
- package/lib/ReactPutListenerQueue.js +0 -54
- 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/ReactLifeCycle.js
CHANGED
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
|
@@ -27,11 +27,11 @@ var ReactUpdates = require("./ReactUpdates");
|
|
|
27
27
|
|
|
28
28
|
var emptyObject = require("./emptyObject");
|
|
29
29
|
var containsNode = require("./containsNode");
|
|
30
|
-
var getReactRootElementInContainer = require("./getReactRootElementInContainer");
|
|
31
30
|
var instantiateReactComponent = require("./instantiateReactComponent");
|
|
32
31
|
var invariant = require("./invariant");
|
|
33
32
|
var setInnerHTML = require("./setInnerHTML");
|
|
34
33
|
var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
|
|
34
|
+
var validateDOMNesting = require("./validateDOMNesting");
|
|
35
35
|
var warning = require("./warning");
|
|
36
36
|
|
|
37
37
|
var SEPARATOR = ReactInstanceHandles.SEPARATOR;
|
|
@@ -41,6 +41,7 @@ var nodeCache = {};
|
|
|
41
41
|
|
|
42
42
|
var ELEMENT_NODE_TYPE = 1;
|
|
43
43
|
var DOC_NODE_TYPE = 9;
|
|
44
|
+
var DOCUMENT_FRAGMENT_NODE_TYPE = 11;
|
|
44
45
|
|
|
45
46
|
/** Mapping from reactRootID to React component instance. */
|
|
46
47
|
var instancesByReactRootID = {};
|
|
@@ -48,7 +49,7 @@ var instancesByReactRootID = {};
|
|
|
48
49
|
/** Mapping from reactRootID to `container` nodes. */
|
|
49
50
|
var containersByReactRootID = {};
|
|
50
51
|
|
|
51
|
-
if (
|
|
52
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
52
53
|
/** __DEV__-only mapping from reactRootID to root elements. */
|
|
53
54
|
var rootElementsByReactRootID = {};
|
|
54
55
|
}
|
|
@@ -72,6 +73,23 @@ function firstDifferenceIndex(string1, string2) {
|
|
|
72
73
|
return string1.length === string2.length ? -1 : minLen;
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @param {DOMElement|DOMDocument} container DOM element that may contain
|
|
78
|
+
* a React component
|
|
79
|
+
* @return {?*} DOM element that may have the reactRoot ID, or null.
|
|
80
|
+
*/
|
|
81
|
+
function getReactRootElementInContainer(container) {
|
|
82
|
+
if (!container) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (container.nodeType === DOC_NODE_TYPE) {
|
|
87
|
+
return container.documentElement;
|
|
88
|
+
} else {
|
|
89
|
+
return container.firstChild;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
75
93
|
/**
|
|
76
94
|
* @param {DOMElement} container DOM element that may contain a React component.
|
|
77
95
|
* @return {?string} A "reactRoot" ID, if a React component is rendered.
|
|
@@ -97,11 +115,7 @@ function getID(node) {
|
|
|
97
115
|
if (nodeCache.hasOwnProperty(id)) {
|
|
98
116
|
var cached = nodeCache[id];
|
|
99
117
|
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)));
|
|
118
|
+
!!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
119
|
|
|
106
120
|
nodeCache[id] = node;
|
|
107
121
|
}
|
|
@@ -179,11 +193,7 @@ function getNodeFromInstance(instance) {
|
|
|
179
193
|
*/
|
|
180
194
|
function isValid(node, id) {
|
|
181
195
|
if (node) {
|
|
182
|
-
(
|
|
183
|
-
internalGetID(node) === id,
|
|
184
|
-
'ReactMount: Unexpected modification of `%s`',
|
|
185
|
-
ATTR_NAME
|
|
186
|
-
) : invariant(internalGetID(node) === id));
|
|
196
|
+
!(internalGetID(node) === id) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'ReactMount: Unexpected modification of `%s`', ATTR_NAME) : invariant(false) : undefined;
|
|
187
197
|
|
|
188
198
|
var container = ReactMount.findReactContainerForID(id);
|
|
189
199
|
if (container && containsNode(container, node)) {
|
|
@@ -220,10 +230,7 @@ function findDeepestCachedAncestorImpl(ancestorID) {
|
|
|
220
230
|
*/
|
|
221
231
|
function findDeepestCachedAncestor(targetID) {
|
|
222
232
|
deepestNodeSoFar = null;
|
|
223
|
-
ReactInstanceHandles.traverseAncestors(
|
|
224
|
-
targetID,
|
|
225
|
-
findDeepestCachedAncestorImpl
|
|
226
|
-
);
|
|
233
|
+
ReactInstanceHandles.traverseAncestors(targetID, findDeepestCachedAncestorImpl);
|
|
227
234
|
|
|
228
235
|
var foundNode = deepestNodeSoFar;
|
|
229
236
|
deepestNodeSoFar = null;
|
|
@@ -239,15 +246,15 @@ function findDeepestCachedAncestor(targetID) {
|
|
|
239
246
|
* @param {ReactReconcileTransaction} transaction
|
|
240
247
|
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
241
248
|
*/
|
|
242
|
-
function mountComponentIntoNode(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
);
|
|
249
|
+
function mountComponentIntoNode(componentInstance, rootID, container, transaction, shouldReuseMarkup, context) {
|
|
250
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
251
|
+
if (context === emptyObject) {
|
|
252
|
+
context = {};
|
|
253
|
+
}
|
|
254
|
+
var tag = container.nodeName.toLowerCase();
|
|
255
|
+
context[validateDOMNesting.ancestorInfoContextKey] = validateDOMNesting.updatedAncestorInfo(null, tag, null);
|
|
256
|
+
}
|
|
257
|
+
var markup = ReactReconciler.mountComponent(componentInstance, rootID, transaction, context);
|
|
251
258
|
componentInstance._isTopLevel = true;
|
|
252
259
|
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
253
260
|
}
|
|
@@ -260,24 +267,34 @@ function mountComponentIntoNode(
|
|
|
260
267
|
* @param {DOMElement} container DOM element to mount into.
|
|
261
268
|
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
262
269
|
*/
|
|
263
|
-
function batchedMountComponentIntoNode(
|
|
264
|
-
componentInstance,
|
|
265
|
-
rootID,
|
|
266
|
-
container,
|
|
267
|
-
shouldReuseMarkup) {
|
|
270
|
+
function batchedMountComponentIntoNode(componentInstance, rootID, container, shouldReuseMarkup, context) {
|
|
268
271
|
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
269
|
-
transaction.perform(
|
|
270
|
-
mountComponentIntoNode,
|
|
271
|
-
null,
|
|
272
|
-
componentInstance,
|
|
273
|
-
rootID,
|
|
274
|
-
container,
|
|
275
|
-
transaction,
|
|
276
|
-
shouldReuseMarkup
|
|
277
|
-
);
|
|
272
|
+
transaction.perform(mountComponentIntoNode, null, componentInstance, rootID, container, transaction, shouldReuseMarkup, context);
|
|
278
273
|
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
279
274
|
}
|
|
280
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Unmounts a component and removes it from the DOM.
|
|
278
|
+
*
|
|
279
|
+
* @param {ReactComponent} instance React component instance.
|
|
280
|
+
* @param {DOMElement} container DOM element to unmount from.
|
|
281
|
+
* @final
|
|
282
|
+
* @internal
|
|
283
|
+
* @see {ReactMount.unmountComponentAtNode}
|
|
284
|
+
*/
|
|
285
|
+
function unmountComponentFromNode(instance, container) {
|
|
286
|
+
ReactReconciler.unmountComponent(instance);
|
|
287
|
+
|
|
288
|
+
if (container.nodeType === DOC_NODE_TYPE) {
|
|
289
|
+
container = container.documentElement;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// http://jsperf.com/emptying-a-node
|
|
293
|
+
while (container.lastChild) {
|
|
294
|
+
container.removeChild(container.lastChild);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
281
298
|
/**
|
|
282
299
|
* Mounting is the process of initializing a React component by creating its
|
|
283
300
|
* representative DOM elements and inserting them into a supplied `container`.
|
|
@@ -308,7 +325,7 @@ var ReactMount = {
|
|
|
308
325
|
* @param {DOMElement} container The `container` being rendered into.
|
|
309
326
|
* @param {function} renderCallback This must be called once to do the render.
|
|
310
327
|
*/
|
|
311
|
-
scrollMonitor: function(container, renderCallback) {
|
|
328
|
+
scrollMonitor: function (container, renderCallback) {
|
|
312
329
|
renderCallback();
|
|
313
330
|
},
|
|
314
331
|
|
|
@@ -319,26 +336,21 @@ var ReactMount = {
|
|
|
319
336
|
* @param {DOMElement} container container to render into
|
|
320
337
|
* @param {?function} callback function triggered on completion
|
|
321
338
|
*/
|
|
322
|
-
_updateRootComponent: function(
|
|
323
|
-
|
|
324
|
-
nextElement,
|
|
325
|
-
container,
|
|
326
|
-
callback) {
|
|
327
|
-
if ("production" !== process.env.NODE_ENV) {
|
|
339
|
+
_updateRootComponent: function (prevComponent, nextElement, container, callback) {
|
|
340
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
328
341
|
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
329
342
|
}
|
|
330
343
|
|
|
331
|
-
ReactMount.scrollMonitor(container, function() {
|
|
344
|
+
ReactMount.scrollMonitor(container, function () {
|
|
332
345
|
ReactUpdateQueue.enqueueElementInternal(prevComponent, nextElement);
|
|
333
346
|
if (callback) {
|
|
334
347
|
ReactUpdateQueue.enqueueCallbackInternal(prevComponent, callback);
|
|
335
348
|
}
|
|
336
349
|
});
|
|
337
350
|
|
|
338
|
-
if (
|
|
351
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
339
352
|
// Record the root element in case it later gets transplanted.
|
|
340
|
-
rootElementsByReactRootID[getReactRootID(container)] =
|
|
341
|
-
getReactRootElementInContainer(container);
|
|
353
|
+
rootElementsByReactRootID[getReactRootID(container)] = getReactRootElementInContainer(container);
|
|
342
354
|
}
|
|
343
355
|
|
|
344
356
|
return prevComponent;
|
|
@@ -351,15 +363,8 @@ var ReactMount = {
|
|
|
351
363
|
* @param {DOMElement} container container to render into
|
|
352
364
|
* @return {string} reactRoot ID prefix
|
|
353
365
|
*/
|
|
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
|
-
)));
|
|
366
|
+
_registerComponent: function (nextComponent, container) {
|
|
367
|
+
!(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
368
|
|
|
364
369
|
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
|
|
365
370
|
|
|
@@ -375,44 +380,24 @@ var ReactMount = {
|
|
|
375
380
|
* @param {boolean} shouldReuseMarkup if we should skip the markup insertion
|
|
376
381
|
* @return {ReactComponent} nextComponent
|
|
377
382
|
*/
|
|
378
|
-
_renderNewRootComponent: function(
|
|
379
|
-
nextElement,
|
|
380
|
-
container,
|
|
381
|
-
shouldReuseMarkup
|
|
382
|
-
) {
|
|
383
|
+
_renderNewRootComponent: function (nextElement, container, shouldReuseMarkup, context) {
|
|
383
384
|
// Various parts of our code (such as ReactCompositeComponent's
|
|
384
385
|
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
385
386
|
// 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);
|
|
387
|
+
'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
388
|
|
|
394
389
|
var componentInstance = instantiateReactComponent(nextElement, null);
|
|
395
|
-
var reactRootID = ReactMount._registerComponent(
|
|
396
|
-
componentInstance,
|
|
397
|
-
container
|
|
398
|
-
);
|
|
390
|
+
var reactRootID = ReactMount._registerComponent(componentInstance, container);
|
|
399
391
|
|
|
400
392
|
// The initial render is synchronous but any updates that happen during
|
|
401
393
|
// rendering, in componentWillMount or componentDidMount, will be batched
|
|
402
394
|
// according to the current batching strategy.
|
|
403
395
|
|
|
404
|
-
ReactUpdates.batchedUpdates(
|
|
405
|
-
batchedMountComponentIntoNode,
|
|
406
|
-
componentInstance,
|
|
407
|
-
reactRootID,
|
|
408
|
-
container,
|
|
409
|
-
shouldReuseMarkup
|
|
410
|
-
);
|
|
396
|
+
ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, reactRootID, container, shouldReuseMarkup, context);
|
|
411
397
|
|
|
412
|
-
if (
|
|
398
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
413
399
|
// Record the root element in case it later gets transplanted.
|
|
414
|
-
rootElementsByReactRootID[reactRootID] =
|
|
415
|
-
getReactRootElementInContainer(container);
|
|
400
|
+
rootElementsByReactRootID[reactRootID] = getReactRootElementInContainer(container);
|
|
416
401
|
}
|
|
417
402
|
|
|
418
403
|
return componentInstance;
|
|
@@ -425,61 +410,44 @@ var ReactMount = {
|
|
|
425
410
|
* perform an update on it and only mutate the DOM as necessary to reflect the
|
|
426
411
|
* latest React component.
|
|
427
412
|
*
|
|
413
|
+
* @param {ReactComponent} parentComponent The conceptual parent of this render tree.
|
|
428
414
|
* @param {ReactElement} nextElement Component element to render.
|
|
429
415
|
* @param {DOMElement} container DOM element to render into.
|
|
430
416
|
* @param {?function} callback function triggered on completion
|
|
431
417
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
432
418
|
*/
|
|
433
|
-
|
|
434
|
-
(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
// Check if it quacks like an element
|
|
445
|
-
nextElement != null && nextElement.props !== undefined ?
|
|
446
|
-
' This may be caused by unintentionally loading two independent ' +
|
|
447
|
-
'copies of React.' :
|
|
448
|
-
''
|
|
449
|
-
)
|
|
450
|
-
) : invariant(ReactElement.isValidElement(nextElement)));
|
|
419
|
+
renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
|
420
|
+
!(parentComponent != null && parentComponent._reactInternalInstance != null) ? 'production' !== process.env.NODE_ENV ? invariant(false, 'parentComponent must be a valid React Component') : invariant(false) : undefined;
|
|
421
|
+
return ReactMount._renderSubtreeIntoContainer(parentComponent, nextElement, container, callback);
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
_renderSubtreeIntoContainer: function (parentComponent, nextElement, container, callback) {
|
|
425
|
+
!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.' :
|
|
426
|
+
// Check if it quacks like an element
|
|
427
|
+
nextElement != null && nextElement.props !== undefined ? ' This may be caused by unintentionally loading two independent ' + 'copies of React.' : '') : invariant(false) : undefined;
|
|
428
|
+
|
|
429
|
+
'production' !== process.env.NODE_ENV ? warning(container && container.tagName !== '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;
|
|
451
430
|
|
|
452
431
|
var prevComponent = instancesByReactRootID[getReactRootID(container)];
|
|
453
432
|
|
|
454
433
|
if (prevComponent) {
|
|
455
434
|
var prevElement = prevComponent._currentElement;
|
|
456
435
|
if (shouldUpdateReactComponent(prevElement, nextElement)) {
|
|
457
|
-
return ReactMount._updateRootComponent(
|
|
458
|
-
prevComponent,
|
|
459
|
-
nextElement,
|
|
460
|
-
container,
|
|
461
|
-
callback
|
|
462
|
-
).getPublicInstance();
|
|
436
|
+
return ReactMount._updateRootComponent(prevComponent, nextElement, container, callback).getPublicInstance();
|
|
463
437
|
} else {
|
|
464
438
|
ReactMount.unmountComponentAtNode(container);
|
|
465
439
|
}
|
|
466
440
|
}
|
|
467
441
|
|
|
468
442
|
var reactRootElement = getReactRootElementInContainer(container);
|
|
469
|
-
var containerHasReactMarkup =
|
|
470
|
-
reactRootElement && ReactMount.isRenderedByReact(reactRootElement);
|
|
443
|
+
var containerHasReactMarkup = reactRootElement && ReactMount.isRenderedByReact(reactRootElement);
|
|
471
444
|
|
|
472
|
-
if (
|
|
445
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
473
446
|
if (!containerHasReactMarkup || reactRootElement.nextSibling) {
|
|
474
447
|
var rootElementSibling = reactRootElement;
|
|
475
448
|
while (rootElementSibling) {
|
|
476
449
|
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);
|
|
450
|
+
'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
451
|
break;
|
|
484
452
|
}
|
|
485
453
|
|
|
@@ -489,18 +457,29 @@ var ReactMount = {
|
|
|
489
457
|
}
|
|
490
458
|
|
|
491
459
|
var shouldReuseMarkup = containerHasReactMarkup && !prevComponent;
|
|
492
|
-
|
|
493
|
-
var component = ReactMount._renderNewRootComponent(
|
|
494
|
-
nextElement,
|
|
495
|
-
container,
|
|
496
|
-
shouldReuseMarkup
|
|
497
|
-
).getPublicInstance();
|
|
460
|
+
var component = ReactMount._renderNewRootComponent(nextElement, container, shouldReuseMarkup, parentComponent != null ? parentComponent._reactInternalInstance._processChildContext(parentComponent._reactInternalInstance._context) : emptyObject).getPublicInstance();
|
|
498
461
|
if (callback) {
|
|
499
462
|
callback.call(component);
|
|
500
463
|
}
|
|
501
464
|
return component;
|
|
502
465
|
},
|
|
503
466
|
|
|
467
|
+
/**
|
|
468
|
+
* Renders a React component into the DOM in the supplied `container`.
|
|
469
|
+
*
|
|
470
|
+
* If the React component was previously rendered into `container`, this will
|
|
471
|
+
* perform an update on it and only mutate the DOM as necessary to reflect the
|
|
472
|
+
* latest React component.
|
|
473
|
+
*
|
|
474
|
+
* @param {ReactElement} nextElement Component element to render.
|
|
475
|
+
* @param {DOMElement} container DOM element to render into.
|
|
476
|
+
* @param {?function} callback function triggered on completion
|
|
477
|
+
* @return {ReactComponent} Component instance rendered in `container`.
|
|
478
|
+
*/
|
|
479
|
+
render: function (nextElement, container, callback) {
|
|
480
|
+
return ReactMount._renderSubtreeIntoContainer(null, nextElement, container, callback);
|
|
481
|
+
},
|
|
482
|
+
|
|
504
483
|
/**
|
|
505
484
|
* Constructs a component instance of `constructor` with `initialProps` and
|
|
506
485
|
* renders it into the supplied `container`.
|
|
@@ -510,7 +489,7 @@ var ReactMount = {
|
|
|
510
489
|
* @param {DOMElement} container DOM element to render into.
|
|
511
490
|
* @return {ReactComponent} Component instance rendered in `container`.
|
|
512
491
|
*/
|
|
513
|
-
constructAndRenderComponent: function(constructor, props, container) {
|
|
492
|
+
constructAndRenderComponent: function (constructor, props, container) {
|
|
514
493
|
var element = ReactElement.createElement(constructor, props);
|
|
515
494
|
return ReactMount.render(element, container);
|
|
516
495
|
},
|
|
@@ -524,13 +503,9 @@ var ReactMount = {
|
|
|
524
503
|
* @param {string} id ID of the DOM element to render into.
|
|
525
504
|
* @return {ReactComponent} Component instance rendered in the container node.
|
|
526
505
|
*/
|
|
527
|
-
constructAndRenderComponentByID: function(constructor, props, id) {
|
|
506
|
+
constructAndRenderComponentByID: function (constructor, props, id) {
|
|
528
507
|
var domNode = document.getElementById(id);
|
|
529
|
-
|
|
530
|
-
domNode,
|
|
531
|
-
'Tried to get element with id of "%s" but it is not present on the page.',
|
|
532
|
-
id
|
|
533
|
-
) : invariant(domNode));
|
|
508
|
+
!domNode ? 'production' !== process.env.NODE_ENV ? invariant(false, 'Tried to get element with id of "%s" but it is not present on the page.', id) : invariant(false) : undefined;
|
|
534
509
|
return ReactMount.constructAndRenderComponent(constructor, props, domNode);
|
|
535
510
|
},
|
|
536
511
|
|
|
@@ -542,7 +517,7 @@ var ReactMount = {
|
|
|
542
517
|
* @param {DOMElement} container DOM element to register as a container.
|
|
543
518
|
* @return {string} The "reactRoot" ID of elements rendered within.
|
|
544
519
|
*/
|
|
545
|
-
registerContainer: function(container) {
|
|
520
|
+
registerContainer: function (container) {
|
|
546
521
|
var reactRootID = getReactRootID(container);
|
|
547
522
|
if (reactRootID) {
|
|
548
523
|
// If one exists, make sure it is a valid "reactRoot" ID.
|
|
@@ -563,64 +538,29 @@ var ReactMount = {
|
|
|
563
538
|
* @return {boolean} True if a component was found in and unmounted from
|
|
564
539
|
* `container`
|
|
565
540
|
*/
|
|
566
|
-
unmountComponentAtNode: function(container) {
|
|
541
|
+
unmountComponentAtNode: function (container) {
|
|
567
542
|
// Various parts of our code (such as ReactCompositeComponent's
|
|
568
543
|
// _renderValidatedComponent) assume that calls to render aren't nested;
|
|
569
544
|
// verify that that's the case. (Strictly speaking, unmounting won't cause a
|
|
570
545
|
// 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
|
-
)));
|
|
546
|
+
'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;
|
|
547
|
+
|
|
548
|
+
!(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
549
|
|
|
588
550
|
var reactRootID = getReactRootID(container);
|
|
589
551
|
var component = instancesByReactRootID[reactRootID];
|
|
590
552
|
if (!component) {
|
|
591
553
|
return false;
|
|
592
554
|
}
|
|
593
|
-
|
|
555
|
+
ReactUpdates.batchedUpdates(unmountComponentFromNode, component, container);
|
|
594
556
|
delete instancesByReactRootID[reactRootID];
|
|
595
557
|
delete containersByReactRootID[reactRootID];
|
|
596
|
-
if (
|
|
558
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
597
559
|
delete rootElementsByReactRootID[reactRootID];
|
|
598
560
|
}
|
|
599
561
|
return true;
|
|
600
562
|
},
|
|
601
563
|
|
|
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
564
|
/**
|
|
625
565
|
* Finds the container DOM element that contains React component to which the
|
|
626
566
|
* supplied DOM `id` belongs.
|
|
@@ -628,36 +568,26 @@ var ReactMount = {
|
|
|
628
568
|
* @param {string} id The ID of an element rendered by a React component.
|
|
629
569
|
* @return {?DOMElement} DOM element that contains the `id`.
|
|
630
570
|
*/
|
|
631
|
-
findReactContainerForID: function(id) {
|
|
571
|
+
findReactContainerForID: function (id) {
|
|
632
572
|
var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(id);
|
|
633
573
|
var container = containersByReactRootID[reactRootID];
|
|
634
574
|
|
|
635
|
-
if (
|
|
575
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
636
576
|
var rootElement = rootElementsByReactRootID[reactRootID];
|
|
637
577
|
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
|
|
578
|
+
'production' !== process.env.NODE_ENV ? warning(
|
|
579
|
+
// Call internalGetID here because getID calls isValid which calls
|
|
644
580
|
// findReactContainerForID (this function).
|
|
645
|
-
internalGetID(rootElement) === reactRootID)
|
|
646
|
-
|
|
581
|
+
internalGetID(rootElement) === reactRootID, 'ReactMount: Root element ID differed from reactRootID.') : undefined;
|
|
647
582
|
var containerChild = container.firstChild;
|
|
648
|
-
if (containerChild &&
|
|
649
|
-
reactRootID === internalGetID(containerChild)) {
|
|
583
|
+
if (containerChild && reactRootID === internalGetID(containerChild)) {
|
|
650
584
|
// If the container has a new child with the same ID as the old
|
|
651
585
|
// root element, then rootElementsByReactRootID[reactRootID] is
|
|
652
586
|
// just stale and needs to be updated. The case that deserves a
|
|
653
587
|
// warning is when the container is empty.
|
|
654
588
|
rootElementsByReactRootID[reactRootID] = containerChild;
|
|
655
589
|
} else {
|
|
656
|
-
|
|
657
|
-
false,
|
|
658
|
-
'ReactMount: Root element has been removed from its original ' +
|
|
659
|
-
'container. New container:', rootElement.parentNode
|
|
660
|
-
) : null);
|
|
590
|
+
'production' !== process.env.NODE_ENV ? warning(false, 'ReactMount: Root element has been removed from its original ' + 'container. New container:', rootElement.parentNode) : undefined;
|
|
661
591
|
}
|
|
662
592
|
}
|
|
663
593
|
}
|
|
@@ -671,7 +601,7 @@ var ReactMount = {
|
|
|
671
601
|
* @param {string} id ID of a DOM node in the React component.
|
|
672
602
|
* @return {DOMElement} Root DOM node of the React component.
|
|
673
603
|
*/
|
|
674
|
-
findReactNodeByID: function(id) {
|
|
604
|
+
findReactNodeByID: function (id) {
|
|
675
605
|
var reactRoot = ReactMount.findReactContainerForID(id);
|
|
676
606
|
return ReactMount.findComponentRoot(reactRoot, id);
|
|
677
607
|
},
|
|
@@ -683,7 +613,7 @@ var ReactMount = {
|
|
|
683
613
|
* @return {boolean} True if the DOM Element appears to be rendered by React.
|
|
684
614
|
* @internal
|
|
685
615
|
*/
|
|
686
|
-
isRenderedByReact: function(node) {
|
|
616
|
+
isRenderedByReact: function (node) {
|
|
687
617
|
if (node.nodeType !== 1) {
|
|
688
618
|
// Not a DOMElement, therefore not a React component
|
|
689
619
|
return false;
|
|
@@ -700,7 +630,7 @@ var ReactMount = {
|
|
|
700
630
|
* @return {?DOMEventTarget}
|
|
701
631
|
* @internal
|
|
702
632
|
*/
|
|
703
|
-
getFirstReactDOM: function(node) {
|
|
633
|
+
getFirstReactDOM: function (node) {
|
|
704
634
|
var current = node;
|
|
705
635
|
while (current && current.parentNode !== current) {
|
|
706
636
|
if (ReactMount.isRenderedByReact(current)) {
|
|
@@ -721,7 +651,7 @@ var ReactMount = {
|
|
|
721
651
|
* @return {DOMEventTarget} DOM node with the supplied `targetID`.
|
|
722
652
|
* @internal
|
|
723
653
|
*/
|
|
724
|
-
findComponentRoot: function(ancestorNode, targetID) {
|
|
654
|
+
findComponentRoot: function (ancestorNode, targetID) {
|
|
725
655
|
var firstChildren = findComponentRootReusableArray;
|
|
726
656
|
var childIndex = 0;
|
|
727
657
|
|
|
@@ -752,7 +682,6 @@ var ReactMount = {
|
|
|
752
682
|
firstChildren.length = childIndex = 0;
|
|
753
683
|
firstChildren.push(child.firstChild);
|
|
754
684
|
}
|
|
755
|
-
|
|
756
685
|
} else {
|
|
757
686
|
// If this child had no ID, then there's a chance that it was
|
|
758
687
|
// injected automatically by the browser, as when a `<table>`
|
|
@@ -777,87 +706,35 @@ var ReactMount = {
|
|
|
777
706
|
|
|
778
707
|
firstChildren.length = 0;
|
|
779
708
|
|
|
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));
|
|
709
|
+
!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
710
|
},
|
|
792
711
|
|
|
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
|
-
)));
|
|
712
|
+
_mountImageIntoNode: function (markup, container, shouldReuseMarkup) {
|
|
713
|
+
!(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
714
|
|
|
803
715
|
if (shouldReuseMarkup) {
|
|
804
716
|
var rootElement = getReactRootElementInContainer(container);
|
|
805
717
|
if (ReactMarkupChecksum.canReuseMarkup(markup, rootElement)) {
|
|
806
718
|
return;
|
|
807
719
|
} else {
|
|
808
|
-
var checksum = rootElement.getAttribute(
|
|
809
|
-
ReactMarkupChecksum.CHECKSUM_ATTR_NAME
|
|
810
|
-
);
|
|
720
|
+
var checksum = rootElement.getAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
811
721
|
rootElement.removeAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME);
|
|
812
722
|
|
|
813
723
|
var rootMarkup = rootElement.outerHTML;
|
|
814
|
-
rootElement.setAttribute(
|
|
815
|
-
ReactMarkupChecksum.CHECKSUM_ATTR_NAME,
|
|
816
|
-
checksum
|
|
817
|
-
);
|
|
724
|
+
rootElement.setAttribute(ReactMarkupChecksum.CHECKSUM_ATTR_NAME, checksum);
|
|
818
725
|
|
|
819
726
|
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);
|
|
727
|
+
var difference = ' (client) ' + markup.substring(diffIndex - 20, diffIndex + 20) + '\n (server) ' + rootMarkup.substring(diffIndex - 20, diffIndex + 20);
|
|
728
|
+
|
|
729
|
+
!(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;
|
|
730
|
+
|
|
731
|
+
if ('production' !== process.env.NODE_ENV) {
|
|
732
|
+
'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
733
|
}
|
|
851
734
|
}
|
|
852
735
|
}
|
|
853
736
|
|
|
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));
|
|
737
|
+
!(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
738
|
|
|
862
739
|
setInnerHTML(container, markup);
|
|
863
740
|
},
|
|
@@ -884,4 +761,4 @@ ReactPerf.measureMethods(ReactMount, 'ReactMount', {
|
|
|
884
761
|
_mountImageIntoNode: '_mountImageIntoNode'
|
|
885
762
|
});
|
|
886
763
|
|
|
887
|
-
module.exports = ReactMount;
|
|
764
|
+
module.exports = ReactMount;
|