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

fix #11759. false positive warning in IE11 when using React.Fragment #11823

Merged
merged 6 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import lowPriorityWarning from 'shared/lowPriorityWarning';
import describeComponentFrame from 'shared/describeComponentFrame';
import getComponentName from 'shared/getComponentName';
import {getIteratorFn, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
import {
getIteratorFn,
REACT_FRAGMENT_TYPE,
isReactSymbol,
} from 'shared/ReactSymbols';
import checkPropTypes from 'prop-types/checkPropTypes';
import warning from 'fbjs/lib/warning';

Expand Down Expand Up @@ -281,7 +285,7 @@ export function createElementWithValidation(type, props, children) {
const validType =
typeof type === 'string' ||
typeof type === 'function' ||
typeof type === 'symbol' ||
isReactSymbol(type) ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave this check as is. It’s a hot path so we can’t do .some() there. It’s also unnecessary because the number check below should cover it.

typeof type === 'number';
// We warn in this case but don't throw. We expect the element creation to
// succeed and there will likely be errors in render.
Expand Down Expand Up @@ -336,7 +340,7 @@ export function createElementWithValidation(type, props, children) {
}
}

if (typeof type === 'symbol' && type === REACT_FRAGMENT_TYPE) {
if (type === REACT_FRAGMENT_TYPE) {
validateFragmentProps(element);
} else {
validatePropTypes(element);
Expand Down
13 changes: 13 additions & 0 deletions packages/shared/ReactSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,16 @@ export function getIteratorFn(maybeIterable: ?any): ?() => ?Iterator<*> {
}
return null;
}

const reactSymbols = [
REACT_ELEMENT_TYPE,
REACT_CALL_TYPE,
REACT_RETURN_TYPE,
REACT_PORTAL_TYPE,
REACT_FRAGMENT_TYPE,
MAYBE_ITERATOR_SYMBOL,
FAUX_ITERATOR_SYMBOL,
];
export function isReactSymbol(type: any) {
return reactSymbols.some(r => type === r);
}