Use Function.prototype.apply in warningWithoutStack (#14107)
console.error.apply() fails in IE9, but I verified this works (and it works everywhere else too). :)
Sophie Alpert committed
Nov 5, 2018 at 11:11 UTC
da04058a91339944e89b6e071765db06863233be
1 file changed
+5
-37
packages/shared/warningWithoutStack.js
+5
-37
@@ -32,44 +32,12 @@ if (__DEV__) {
32
return;
33
}
34
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);
37
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);
41
}
42
try {
43
// --- Welcome to debugging React ---