Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor validateDOMNesting a bit #13300

Merged
merged 1 commit into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/react-dom/src/client/ReactDOMFiberOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import warning from 'shared/warning';
import validateDOMNesting from './validateDOMNesting';
import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';

let didWarnSelectedSetOnOption = false;

Expand Down Expand Up @@ -53,10 +53,7 @@ export function validateProps(element: Element, props: Object) {
// We don't have access to the real one because the <option>
// fiber has already been popped, and threading it through
// is needlessly annoying.
const ancestorInfo = validateDOMNesting.updatedAncestorInfo(
null,
'option',
);
const ancestorInfo = updatedAncestorInfo(null, 'option');
validateDOMNesting(child.type, null, ancestorInfo);
});
}
Expand Down
8 changes: 2 additions & 6 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as ReactDOMComponentTree from './ReactDOMComponentTree';
import * as ReactDOMFiberComponent from './ReactDOMFiberComponent';
import * as ReactInputSelection from './ReactInputSelection';
import setTextContent from './setTextContent';
import validateDOMNesting from './validateDOMNesting';
import {validateDOMNesting, updatedAncestorInfo} from './validateDOMNesting';
import * as ReactBrowserEventEmitter from '../events/ReactBrowserEventEmitter';
import {getChildNamespace} from '../shared/DOMNamespaces';
import {
Expand Down Expand Up @@ -62,7 +62,6 @@ const {
warnForInsertedHydratedElement,
warnForInsertedHydratedText,
} = ReactDOMFiberComponent;
const {updatedAncestorInfo} = validateDOMNesting;
const {precacheFiberNode, updateFiberProps} = ReactDOMComponentTree;

let SUPPRESS_HYDRATION_WARNING;
Expand Down Expand Up @@ -113,7 +112,7 @@ export function getRootHostContext(
}
if (__DEV__) {
const validatedTag = type.toLowerCase();
const ancestorInfo = updatedAncestorInfo(null, validatedTag, null);
const ancestorInfo = updatedAncestorInfo(null, validatedTag);
return {namespace, ancestorInfo};
}
return namespace;
Expand All @@ -130,7 +129,6 @@ export function getChildHostContext(
const ancestorInfo = updatedAncestorInfo(
parentHostContextDev.ancestorInfo,
type,
null,
);
return {namespace, ancestorInfo};
}
Expand Down Expand Up @@ -175,7 +173,6 @@ export function createInstance(
const ownAncestorInfo = updatedAncestorInfo(
hostContextDev.ancestorInfo,
type,
null,
);
validateDOMNesting(null, string, ownAncestorInfo);
}
Expand Down Expand Up @@ -231,7 +228,6 @@ export function prepareUpdate(
const ownAncestorInfo = updatedAncestorInfo(
hostContextDev.ancestorInfo,
type,
null,
);
validateDOMNesting(null, string, ownAncestorInfo);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/react-dom/src/client/validateDOMNesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import warningWithoutStack from 'shared/warningWithoutStack';
import {getCurrentFiberStackInDev} from 'react-reconciler/src/ReactCurrentFiber';

let validateDOMNesting = () => {};
let updatedAncestorInfo = () => {};

if (__DEV__) {
// This validation code was written based on the HTML5 parsing spec:
Expand Down Expand Up @@ -158,9 +159,9 @@ if (__DEV__) {
dlItemTagAutoclosing: null,
};

const updatedAncestorInfo = function(oldInfo, tag, instance) {
updatedAncestorInfo = function(oldInfo, tag) {
let ancestorInfo = {...(oldInfo || emptyAncestorInfo)};
let info = {tag: tag, instance: instance};
let info = {tag};

if (inScopeTags.indexOf(tag) !== -1) {
ancestorInfo.aTagInScope = null;
Expand Down Expand Up @@ -477,9 +478,6 @@ if (__DEV__) {
);
}
};

// TODO: turn this into a named export
validateDOMNesting.updatedAncestorInfo = updatedAncestorInfo;
}

export default validateDOMNesting;
export {updatedAncestorInfo, validateDOMNesting};