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

Prevent performance regression in DEV due to warning arguments #7461

Merged
merged 2 commits into from
Aug 10, 2016
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
16 changes: 9 additions & 7 deletions src/isomorphic/classic/element/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ var ReactElementValidator = {
(type !== null && typeof type === 'object');
// We warn in this case but don't throw. We expect the element creation to
// succeed and there will likely be errors in render.
warning(
validType,
'React.createElement: type should not be null, undefined, boolean, or ' +
'number. It should be a string (for DOM elements) or a ReactClass ' +
'(for composite components).%s',
getDeclarationErrorAddendum()
);
if (!validType) {
warning(
false,
'React.createElement: type should not be null, undefined, boolean, or ' +
'number. It should be a string (for DOM elements) or a ReactClass ' +
'(for composite components).%s',
getDeclarationErrorAddendum()
);
}

var element = ReactElement.createElement.apply(this, arguments);

Expand Down
9 changes: 5 additions & 4 deletions src/renderers/dom/client/wrappers/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,18 @@ function checkSelectPropTypes(inst, props) {
if (props[propName] == null) {
continue;
}
if (props.multiple) {
var isArray = Array.isArray(props[propName]);
if (props.multiple && !isArray) {
warning(
Array.isArray(props[propName]),
false,
'The `%s` prop supplied to <select> must be an array if ' +
'`multiple` is true.%s',
propName,
getDeclarationErrorAddendum(owner)
);
} else {
} else if (!props.multiple && isArray) {
warning(
!Array.isArray(props[propName]),
false,
'The `%s` prop supplied to <select> must be a scalar ' +
'value if `multiple` is false.%s',
propName,
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/dom/shared/hooks/ReactDOMUnknownPropertyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ if (__DEV__) {

if (standardName != null) {
warning(
standardName == null,
false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are just consistency changes. The original code is kinda odd with two checks.

'Unknown DOM property %s. Did you mean %s?%s',
name,
standardName,
Expand All @@ -78,7 +78,7 @@ if (__DEV__) {
return true;
} else if (registrationName != null) {
warning(
registrationName == null,
false,
'Unknown event handler property %s. Did you mean `%s`?%s',
name,
registrationName,
Expand Down
12 changes: 7 additions & 5 deletions src/renderers/shared/hooks/ReactChildrenMutationWarningHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ function handleElement(debugID, element) {
isMutated = true;
}
}
warning(
Array.isArray(element._shadowChildren) && !isMutated,
'Component\'s children should not be mutated.%s',
ReactComponentTreeHook.getStackAddendumByID(debugID),
);
if (!Array.isArray(element._shadowChildren) || isMutated) {
warning(
false,
'Component\'s children should not be mutated.%s',
ReactComponentTreeHook.getStackAddendumByID(debugID),
);
}
}

var ReactDOMUnknownPropertyHook = {
Expand Down
18 changes: 10 additions & 8 deletions src/renderers/shared/stack/reconciler/ReactChildReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ function instantiateChild(childInstances, child, name, selfDebugID) {
if (!ReactComponentTreeHook) {
ReactComponentTreeHook = require('ReactComponentTreeHook');
}
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
KeyEscapeUtils.unescape(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID)
);
if (!keyUnique) {
warning(
false,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
KeyEscapeUtils.unescape(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID)
);
}
}
if (child != null && keyUnique) {
childInstances[name] = instantiateReactComponent(child, true);
Expand Down
18 changes: 10 additions & 8 deletions src/shared/utils/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ function flattenSingleChildIntoContext(
if (!ReactComponentTreeHook) {
ReactComponentTreeHook = require('ReactComponentTreeHook');
}
warning(
keyUnique,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
KeyEscapeUtils.unescape(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID)
);
if (!keyUnique) {
warning(
false,
'flattenChildren(...): Encountered two children with the same key, ' +
'`%s`. Child keys must be unique; when two children share a key, only ' +
'the first child will be used.%s',
KeyEscapeUtils.unescape(name),
ReactComponentTreeHook.getStackAddendumByID(selfDebugID)
);
}
}
if (keyUnique && child != null) {
result[name] = child;
Expand Down