Throw a caught error in the default warning module
This throws an error that is immediately caught. This allows you to use the debugger's "break on caught exception" feature to break on warnings. This should help with tracking down these warnings using the stack. However, it could also add more noise to other debugging pattern.
Sebastian Markbage committed
Dec 23, 2014 at 14:21 UTC
f1bab136d07a6d50901ee7aa5d7d2267ccb855fb
1 file changed
+8
-1
src/vendor/core/warning.js
+8
-1
@@ -33,7 +33,14 @@ if (__DEV__) {
33
34
if (!condition) {
35
var argIndex = 0;
36
- console.warn('Warning: ' + format.replace(/%s/g, () => args[argIndex++]));
36
+ var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
37
+ console.warn(message);
38
+ try {
39
+ // --- Welcome to debugging React ---
40
+ // This error was thrown as a convenience so that you can use this stack
41
+ // to find the callsite that caused this warning to fire.
42
+ throw new Error(message);
43
+ } catch(x) {}
44
}
45
};
46
}