@samitouri / QOS-React-2 / commits / 6ac91d24c4

Improve low priority warning (#9754)

* Add back caught error and other checks to 'lowPriorityWarning' **what is the change?:** This change makes 'lowPriorityWarning' an exact copy of 'warning.js' from https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js where before we had skipped some checks from that module. - Adds an error which we catch, in order to let people find the error and resulting stack trace when using devtools with 'pause on caught errors' checked. - Adds check that 'format' argument is passed **why make this change?:** - To maintain a closer fork to 'warning.js' - To allow easier debugging using 'pause on caught errors' - To validate inputs to 'lowPriorityWarning' **test plan:** `yarn test` **issue:** * Update results.json * Run prettier

Flarnie Marchan committed May 24, 2017 at 07:55 UTC 6ac91d24c4ab88b4cfc6103b237e507401fa3ca1
2 files changed +28 -11
scripts/rollup/results.json
+8 -8
@@ -1,8 +1,8 @@
1 {
2 "bundleSizes": {
3 "react.development.js (UMD_DEV)": {
4 - "size": 125119,
5 - "gzip": 31339
4 + "size": 125800,
5 + "gzip": 31378
6 },
7 "react.production.min.js (UMD_PROD)": {
8 "size": 15753,
@@ -33,24 +33,24 @@
33 "gzip": 29313
34 },
35 "react.development.js (NODE_DEV)": {
36 - "size": 71914,
37 - "gzip": 18276
36 + "size": 72595,
37 + "gzip": 18499
38 },
39 "react.production.min.js (NODE_PROD)": {
40 "size": 9195,
41 "gzip": 3614
42 },
43 "React-dev.js (FB_DEV)": {
44 - "size": 73423,
45 - "gzip": 18751
44 + "size": 74104,
45 + "gzip": 18972
46 },
47 "React-prod.js (FB_PROD)": {
48 "size": 36836,
49 "gzip": 9248
50 },
51 "ReactDOMStack-dev.js (FB_DEV)": {
52 - "size": 496986,
53 - "gzip": 118763
52 + "size": 497667,
53 + "gzip": 118999
54 },
55 "ReactDOMStack-prod.js (FB_PROD)": {
56 "size": 353129,
src/shared/utils/lowPriorityWarning.js
+20 -3
@@ -19,7 +19,6 @@
19 * and do nothing when 'console' is not supported.
20 * This really simplifies the code.
21 * ---
22 - *
22 * Similar to invariant but only logs a warning if the condition is not met.
23 * This can be used to log issues in development environments in critical
24 * paths. Removing the logging code for production environments will keep the
@@ -29,12 +28,30 @@
28 var lowPriorityWarning = function() {};
29
30 if (__DEV__) {
32 - lowPriorityWarning = function(condition, format, ...args) {
31 + const printWarning = function(format, ...args) {
32 var argIndex = 0;
33 var message = 'Warning: ' + format.replace(/%s/g, () => args[argIndex++]);
35 - if (!condition && typeof console !== 'undefined') {
34 + if (typeof console !== 'undefined') {
35 console.warn(message);
36 }
37 + try {
38 + // --- Welcome to debugging React ---
39 + // This error was thrown as a convenience so that you can use this stack
40 + // to find the callsite that caused this warning to fire.
41 + throw new Error(message);
42 + } catch (x) {}
43 + };
44 +
45 + lowPriorityWarning = function(condition, format, ...args) {
46 + if (format === undefined) {
47 + throw new Error(
48 + '`warning(condition, format, ...args)` requires a warning ' +
49 + 'message argument',
50 + );
51 + }
52 + if (!condition) {
53 + printWarning(format, ...args);
54 + }
55 };
56 }
57