Skip to content

Fix warning without stack for ie9 #13620

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

Merged
merged 3 commits into from
Sep 12, 2018
Merged
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
46 changes: 44 additions & 2 deletions packages/shared/warningWithoutStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,54 @@ if (__DEV__) {
'message argument',
);
}
if (args.length > 8) {
// Check before the condition to catch violations early.
throw new Error(
'warningWithoutStack() currently supports at most 8 arguments.',
);
}
if (condition) {
return;
}
if (typeof console !== 'undefined') {
const stringArgs = args.map(item => '' + item);
console.error('Warning: ' + format, ...stringArgs);
const [a, b, c, d, e, f, g, h] = args.map(item => '' + item);
const message = 'Warning: ' + format;

// We intentionally don't use spread (or .apply) because it breaks IE11:
// https://github.com/facebook/react/issues/13610
switch (args.length) {
case 0:
console.error(message);
break;
case 1:
console.error(message, a);
break;
case 2:
console.error(message, a, b);
break;
case 3:
console.error(message, a, b, c);
break;
case 4:
console.error(message, a, b, c, d);
break;
case 5:
console.error(message, a, b, c, d, e);
break;
case 6:
console.error(message, a, b, c, d, e, f);
break;
case 7:
console.error(message, a, b, c, d, e, f, g);
break;
case 8:
console.error(message, a, b, c, d, e, f, g, h);
break;
default:
throw new Error(
'warningWithoutStack() currently supports at most 8 arguments.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need to do this again? I mean, we have done the args.length > 8 check, we won't reach this branch

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really necessary. Just left here for exhaustiveness of switch. It should never happen.

);
}
}
try {
// --- Welcome to debugging React ---
Expand Down