Skip to content

Commit da04058

Browse files
authored
Use Function.prototype.apply in warningWithoutStack (#14107)
console.error.apply() fails in IE9, but I verified this works (and it works everywhere else too). :)
1 parent fd1256a commit da04058

File tree

1 file changed

+5
-37
lines changed

1 file changed

+5
-37
lines changed

packages/shared/warningWithoutStack.js

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,12 @@ if (__DEV__) {
3232
return;
3333
}
3434
if (typeof console !== 'undefined') {
35-
const [a, b, c, d, e, f, g, h] = args.map(item => '' + item);
36-
const message = 'Warning: ' + format;
35+
const argsWithFormat = args.map(item => '' + item);
36+
argsWithFormat.unshift('Warning: ' + format);
3737

38-
// We intentionally don't use spread (or .apply) because it breaks IE9:
39-
// https://github.com/facebook/react/issues/13610
40-
switch (args.length) {
41-
case 0:
42-
console.error(message);
43-
break;
44-
case 1:
45-
console.error(message, a);
46-
break;
47-
case 2:
48-
console.error(message, a, b);
49-
break;
50-
case 3:
51-
console.error(message, a, b, c);
52-
break;
53-
case 4:
54-
console.error(message, a, b, c, d);
55-
break;
56-
case 5:
57-
console.error(message, a, b, c, d, e);
58-
break;
59-
case 6:
60-
console.error(message, a, b, c, d, e, f);
61-
break;
62-
case 7:
63-
console.error(message, a, b, c, d, e, f, g);
64-
break;
65-
case 8:
66-
console.error(message, a, b, c, d, e, f, g, h);
67-
break;
68-
default:
69-
throw new Error(
70-
'warningWithoutStack() currently supports at most 8 arguments.',
71-
);
72-
}
38+
// We intentionally don't use spread (or .apply) directly because it
39+
// breaks IE9: https://github.com/facebook/react/issues/13610
40+
Function.prototype.apply.call(console.error, console, argsWithFormat);
7341
}
7442
try {
7543
// --- Welcome to debugging React ---

0 commit comments

Comments
 (0)