Skip to content

Commit d400d6d

Browse files
NE-SmallTownnhunzaker
authored andcommitted
Replace magic number 1 with ELEMENT_NODE (#13479)
* Replace magic number 1 with ELEMENT_NODE * Add flow pragma to HTMLNodeType
1 parent 340bfd9 commit d400d6d

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

packages/react-dom/src/client/ReactDOM.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ const ReactDOM: Object = {
694694

695695
// Check if the container itself is a React root node.
696696
const isContainerReactRoot =
697-
container.nodeType === 1 &&
697+
container.nodeType === ELEMENT_NODE &&
698698
isValidContainer(container.parentNode) &&
699699
!!container.parentNode._reactRootContainer;
700700

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export function didNotHydrateContainerInstance(
530530
instance: Instance | TextInstance,
531531
) {
532532
if (__DEV__) {
533-
if (instance.nodeType === 1) {
533+
if (instance.nodeType === ELEMENT_NODE) {
534534
warnForDeletedHydratableElement(parentContainer, (instance: any));
535535
} else {
536536
warnForDeletedHydratableText(parentContainer, (instance: any));
@@ -545,7 +545,7 @@ export function didNotHydrateInstance(
545545
instance: Instance | TextInstance,
546546
) {
547547
if (__DEV__ && parentProps[SUPPRESS_HYDRATION_WARNING] !== true) {
548-
if (instance.nodeType === 1) {
548+
if (instance.nodeType === ELEMENT_NODE) {
549549
warnForDeletedHydratableElement(parentInstance, (instance: any));
550550
} else {
551551
warnForDeletedHydratableText(parentInstance, (instance: any));

packages/react-dom/src/shared/HTMLNodeType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
68
*/
79

810
/**

packages/react-dom/src/test-utils/ReactTestUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import SyntheticEvent from 'events/SyntheticEvent';
2121
import invariant from 'shared/invariant';
2222
import lowPriorityWarning from 'shared/lowPriorityWarning';
23-
23+
import {ELEMENT_NODE} from '../shared/HTMLNodeType';
2424
import * as DOMTopLevelEventTypes from '../events/DOMTopLevelEventTypes';
2525

2626
const {findDOMNode} = ReactDOM;
@@ -124,7 +124,7 @@ function validateClassInstance(inst, methodName) {
124124
const stringified = '' + inst;
125125
if (Array.isArray(inst)) {
126126
received = 'an array';
127-
} else if (inst && inst.nodeType === 1 && inst.tagName) {
127+
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
128128
received = 'a DOM node';
129129
} else if (stringified === '[object Object]') {
130130
received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
@@ -169,7 +169,7 @@ const ReactTestUtils = {
169169
},
170170

171171
isDOMComponent: function(inst) {
172-
return !!(inst && inst.nodeType === 1 && inst.tagName);
172+
return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
173173
},
174174

175175
isDOMComponentElement: function(inst) {

0 commit comments

Comments
 (0)