@samitouri / QOS-React / commits / d400d6d5ef

Replace magic number 1 with ELEMENT_NODE (#13479)

* Replace magic number 1 with ELEMENT_NODE * Add flow pragma to HTMLNodeType

Heaven committed Aug 27, 2018 at 23:16 UTC d400d6d5ef056622ed4de4da00f97bde144c6f55
4 files changed +8 -6
packages/react-dom/src/client/ReactDOM.js
+1 -1
@@ -694,7 +694,7 @@ const ReactDOM: Object = {
694
695 // Check if the container itself is a React root node.
696 const isContainerReactRoot =
697 - container.nodeType === 1 &&
697 + container.nodeType === ELEMENT_NODE &&
698 isValidContainer(container.parentNode) &&
699 !!container.parentNode._reactRootContainer;
700
packages/react-dom/src/client/ReactDOMHostConfig.js
+2 -2
@@ -530,7 +530,7 @@ export function didNotHydrateContainerInstance(
530 instance: Instance | TextInstance,
531 ) {
532 if (__DEV__) {
533 - if (instance.nodeType === 1) {
533 + if (instance.nodeType === ELEMENT_NODE) {
534 warnForDeletedHydratableElement(parentContainer, (instance: any));
535 } else {
536 warnForDeletedHydratableText(parentContainer, (instance: any));
@@ -545,7 +545,7 @@ export function didNotHydrateInstance(
545 instance: Instance | TextInstance,
546 ) {
547 if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
548 - if (instance.nodeType === 1) {
548 + if (instance.nodeType === ELEMENT_NODE) {
549 warnForDeletedHydratableElement(parentInstance, (instance: any));
550 } else {
551 warnForDeletedHydratableText(parentInstance, (instance: any));
packages/react-dom/src/shared/HTMLNodeType.js
+2
@@ -3,6 +3,8 @@
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 */
9
10 /**
packages/react-dom/src/test-utils/ReactTestUtils.js
+3 -3
@@ -20,7 +20,7 @@ import {
20 import SyntheticEvent from 'events/SyntheticEvent';
21 import invariant from 'shared/invariant';
22 import lowPriorityWarning from 'shared/lowPriorityWarning';
23 -
23 +import {ELEMENT_NODE} from '../shared/HTMLNodeType';
24 import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
25
26 const {findDOMNode} = ReactDOM;
@@ -124,7 +124,7 @@ function validateClassInstance(inst, methodName) {
124 const stringified = '' + inst;
125 if (Array.isArray(inst)) {
126 received = 'an array';
127 - } else if (inst && inst.nodeType === 1 && inst.tagName) {
127 + } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
128 received = 'a DOM node';
129 } else if (stringified === '[object Object]') {
130 received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
@@ -169,7 +169,7 @@ const ReactTestUtils = {
169 },
170
171 isDOMComponent: function(inst) {
172 - return !!(inst && inst.nodeType === 1 && inst.tagName);
172 + return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
173 },
174
175 isDOMComponentElement: function(inst) {