@samitouri / QOS-React / commits / 28cd494bdf

Refactor validateDOMNesting a bit (#13300)

Dan Abramov committed Aug 1, 2018 at 17:08 UTC 28cd494bdfcae0282e596211e982e120f60168f9
3 files changed +8 -17
packages/react-dom/src/client/ReactDOMFiberOption.js
+2 -5
@@ -9,7 +9,7 @@
9
10 import React from 'react';
11 import warning from 'shared/warning';
12 -import validateDOMNesting from './validateDOMNesting';
12 +import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
13
14 let didWarnSelectedSetOnOption = false;
15
@@ -53,10 +53,7 @@ export function validateProps(element: Element, props: Object) {
53 // We don't have access to the real one because the <option>
54 // fiber has already been popped, and threading it through
55 // is needlessly annoying.
56 - const ancestorInfo = validateDOMNesting.updatedAncestorInfo(
57 - null,
58 - 'option',
59 - );
56 + const ancestorInfo = updatedAncestorInfo(null, 'option');
57 validateDOMNesting(child.type, null, ancestorInfo);
58 });
59 }
packages/react-dom/src/client/ReactDOMHostConfig.js
+2 -6
@@ -13,7 +13,7 @@ import * as ReactDOMComponentTree from './ReactDOMComponentTree';
13 import * as ReactDOMFiberComponent from './ReactDOMFiberComponent';
14 import * as ReactInputSelection from './ReactInputSelection';
15 import setTextContent from './setTextContent';
16 -import validateDOMNesting from './validateDOMNesting';
16 +import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
17 import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
18 import {getChildNamespace} from '../shared/DOMNamespaces';
19 import {
@@ -62,7 +62,6 @@ const {
62 warnForInsertedHydratedElement,
63 warnForInsertedHydratedText,
64 } = ReactDOMFiberComponent;
65 -const {updatedAncestorInfo} = validateDOMNesting;
65 const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;
66
67 let SUPPRESS_HYDRATION_WARNING;
@@ -113,7 +112,7 @@ export function getRootHostContext(
112 }
113 if (__DEV__) {
114 const validatedTag = type.toLowerCase();
116 - const ancestorInfo = updatedAncestorInfo(null, validatedTag, null);
115 + const ancestorInfo = updatedAncestorInfo(null, validatedTag);
116 return {namespace, ancestorInfo};
117 }
118 return namespace;
@@ -130,7 +129,6 @@ export function getChildHostContext(
129 const ancestorInfo = updatedAncestorInfo(
130 parentHostContextDev.ancestorInfo,
131 type,
133 - null,
132 );
133 return {namespace, ancestorInfo};
134 }
@@ -175,7 +173,6 @@ export function createInstance(
173 const ownAncestorInfo = updatedAncestorInfo(
174 hostContextDev.ancestorInfo,
175 type,
178 - null,
176 );
177 validateDOMNesting(null, string, ownAncestorInfo);
178 }
@@ -231,7 +228,6 @@ export function prepareUpdate(
228 const ownAncestorInfo = updatedAncestorInfo(
229 hostContextDev.ancestorInfo,
230 type,
234 - null,
231 );
232 validateDOMNesting(null, string, ownAncestorInfo);
233 }
packages/react-dom/src/client/validateDOMNesting.js
+4 -6
@@ -10,6 +10,7 @@ import warningWithoutStack from 'shared/warningWithoutStack';
10 import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber';
11
12 let validateDOMNesting = () => {};
13 +let updatedAncestorInfo = () => {};
14
15 if (__DEV__) {
16 // This validation code was written based on the HTML5 parsing spec:
@@ -158,9 +159,9 @@ if (__DEV__) {
159 dlItemTagAutoclosing: null,
160 };
161
161 - const updatedAncestorInfo = function(oldInfo, tag, instance) {
162 + updatedAncestorInfo = function(oldInfo, tag) {
163 let ancestorInfo = {...(oldInfo || emptyAncestorInfo)};
163 - let info = {tag: tag, instance: instance};
164 + let info = {tag};
165
166 if (inScopeTags.indexOf(tag) !== -1) {
167 ancestorInfo.aTagInScope = null;
@@ -477,9 +478,6 @@ if (__DEV__) {
478 );
479 }
480 };
480 -
481 - // TODO: turn this into a named export
482 - validateDOMNesting.updatedAncestorInfo = updatedAncestorInfo;
481 }
482
485 -export default validateDOMNesting;
483 +export {updatedAncestorInfo, validateDOMNesting};