Skip to content

Commit 28cd494

Browse files
authored
Refactor validateDOMNesting a bit (#13300)
1 parent b381f41 commit 28cd494

3 files changed

Lines changed: 8 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import React from 'react';
1111
import warning from 'shared/warning';
12-
import validateDOMNesting from './validateDOMNesting';
12+
import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
1313

1414
let didWarnSelectedSetOnOption = false;
1515

@@ -53,10 +53,7 @@ export function validateProps(element: Element, props: Object) {
5353
// We don't have access to the real one because the <option>
5454
// fiber has already been popped, and threading it through
5555
// is needlessly annoying.
56-
const ancestorInfo = validateDOMNesting.updatedAncestorInfo(
57-
null,
58-
'option',
59-
);
56+
const ancestorInfo = updatedAncestorInfo(null, 'option');
6057
validateDOMNesting(child.type, null, ancestorInfo);
6158
});
6259
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as ReactDOMComponentTree from './ReactDOMComponentTree';
1313
import * as ReactDOMFiberComponent from './ReactDOMFiberComponent';
1414
import * as ReactInputSelection from './ReactInputSelection';
1515
import setTextContent from './setTextContent';
16-
import validateDOMNesting from './validateDOMNesting';
16+
import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
1717
import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
1818
import {getChildNamespace} from '../shared/DOMNamespaces';
1919
import {
@@ -62,7 +62,6 @@ const {
6262
warnForInsertedHydratedElement,
6363
warnForInsertedHydratedText,
6464
} = ReactDOMFiberComponent;
65-
const {updatedAncestorInfo} = validateDOMNesting;
6665
const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;
6766

6867
let SUPPRESS_HYDRATION_WARNING;
@@ -113,7 +112,7 @@ export function getRootHostContext(
113112
}
114113
if (__DEV__) {
115114
const validatedTag = type.toLowerCase();
116-
const ancestorInfo = updatedAncestorInfo(null, validatedTag, null);
115+
const ancestorInfo = updatedAncestorInfo(null, validatedTag);
117116
return {namespace, ancestorInfo};
118117
}
119118
return namespace;
@@ -130,7 +129,6 @@ export function getChildHostContext(
130129
const ancestorInfo = updatedAncestorInfo(
131130
parentHostContextDev.ancestorInfo,
132131
type,
133-
null,
134132
);
135133
return {namespace, ancestorInfo};
136134
}
@@ -175,7 +173,6 @@ export function createInstance(
175173
const ownAncestorInfo = updatedAncestorInfo(
176174
hostContextDev.ancestorInfo,
177175
type,
178-
null,
179176
);
180177
validateDOMNesting(null, string, ownAncestorInfo);
181178
}
@@ -231,7 +228,6 @@ export function prepareUpdate(
231228
const ownAncestorInfo = updatedAncestorInfo(
232229
hostContextDev.ancestorInfo,
233230
type,
234-
null,
235231
);
236232
validateDOMNesting(null, string, ownAncestorInfo);
237233
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import warningWithoutStack from 'shared/warningWithoutStack';
1010
import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber';
1111

1212
let validateDOMNesting = () => {};
13+
let updatedAncestorInfo = () => {};
1314

1415
if (__DEV__) {
1516
// This validation code was written based on the HTML5 parsing spec:
@@ -158,9 +159,9 @@ if (__DEV__) {
158159
dlItemTagAutoclosing: null,
159160
};
160161

161-
const updatedAncestorInfo = function(oldInfo, tag, instance) {
162+
updatedAncestorInfo = function(oldInfo, tag) {
162163
let ancestorInfo = {...(oldInfo || emptyAncestorInfo)};
163-
let info = {tag: tag, instance: instance};
164+
let info = {tag};
164165

165166
if (inScopeTags.indexOf(tag) !== -1) {
166167
ancestorInfo.aTagInScope = null;
@@ -477,9 +478,6 @@ if (__DEV__) {
477478
);
478479
}
479480
};
480-
481-
// TODO: turn this into a named export
482-
validateDOMNesting.updatedAncestorInfo = updatedAncestorInfo;
483481
}
484482

485-
export default validateDOMNesting;
483+
export {updatedAncestorInfo, validateDOMNesting};

0 commit comments

Comments
 (0)