@samitouri / QOS-React / commits / 8dfb057881

Unfork invariant and instead use it from reactProdInvariant (#12585)

Dan Abramov committed Apr 9, 2018 at 23:58 UTC 8dfb0578816435a1a72f04506ee20d3c55d0f9bc
3 files changed +21 -71
packages/shared/forks/reactProdInvariant.www.js deleted
-38
@@ -1,38 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
3 - *
4 - * This source code is licensed under the MIT license found in the
5 - * LICENSE file in the root directory of this source tree.
6 - *
7 - * @flow
8 - */
9 -
10 -const invariant = require('invariant');
11 -
12 -function reactProdInvariant(code: string): void {
13 - const argCount = arguments.length - 1;
14 -
15 - let message =
16 - 'Minified React error #' +
17 - code +
18 - '; visit ' +
19 - 'http://reactjs.org/docs/error-decoder.html?invariant=' +
20 - code;
21 -
22 - for (let argIdx = 0; argIdx < argCount; argIdx++) {
23 - message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
24 - }
25 -
26 - message +=
27 - ' for the full message or use the non-minified dev environment' +
28 - ' for full errors and additional helpful warnings.';
29 -
30 - // www doesn't strip this because we mark the React bundle
31 - // with @preserve-invariant-messages docblock.
32 - const i = invariant;
33 - // However, we call it with a different name to avoid
34 - // transforming this file itself as part of React's own build.
35 - i(false, message);
36 -}
37 -
38 -export default reactProdInvariant;
packages/shared/reactProdInvariant.js
+21 -22
@@ -7,6 +7,10 @@
7 * @flow
8 */
9
10 +// Relying on the `invariant()` implementation lets us
11 +// have preserve the format and params in the www builds.
12 +import invariant from 'fbjs/lib/invariant';
13 +
14 /**
15 * WARNING: DO NOT manually require this module.
16 * This is a replacement for `invariant(...)` used by the error code system
@@ -15,30 +19,25 @@
19 */
20 function reactProdInvariant(code: string): void {
21 const argCount = arguments.length - 1;
18 -
19 - let message =
20 - 'Minified React error #' +
21 - code +
22 - '; visit ' +
23 - 'http://reactjs.org/docs/error-decoder.html?invariant=' +
24 - code;
25 -
22 + let url = 'http://reactjs.org/docs/error-decoder.html?invariant=' + code;
23 for (let argIdx = 0; argIdx < argCount; argIdx++) {
27 - message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
24 + url += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
25 }
29 -
30 - message +=
31 - ' for the full message or use the non-minified dev environment' +
32 - ' for full errors and additional helpful warnings.';
33 -
34 - // Note: if you update the code above, don't forget
35 - // to update the www fork in forks/reactProdInvariant.www.js.
36 -
37 - const error: Error & {framesToPop?: number} = new Error(message);
38 - error.name = 'Invariant Violation';
39 - error.framesToPop = 1; // we don't care about reactProdInvariant's own frame
40 -
41 - throw error;
26 + // Rename it so that our build transform doesn't atttempt
27 + // to replace this invariant() call with reactProdInvariant().
28 + const i = invariant;
29 + i(
30 + false,
31 + // The error code is intentionally part of the message (and
32 + // not the format argument) so that we could deduplicate
33 + // different errors in logs based on the code.
34 + 'Minified React error #' +
35 + code +
36 + '; visit %s ' +
37 + 'for the full message or use the non-minified dev environment ' +
38 + 'for full errors and additional helpful warnings. ',
39 + url,
40 + );
41 }
42
43 export default reactProdInvariant;
scripts/rollup/forks.js
-11
@@ -84,17 +84,6 @@ const forks = Object.freeze({
84 }
85 },
86
87 - // Route production invariants on www through the www invariant module.
88 - 'shared/reactProdInvariant': (bundleType, entry) => {
89 - switch (bundleType) {
90 - case FB_DEV:
91 - case FB_PROD:
92 - return 'shared/forks/reactProdInvariant.www.js';
93 - default:
94 - return null;
95 - }
96 - },
97 -
87 // Different dialogs for caught errors.
88 'react-reconciler/src/ReactFiberErrorDialog': (bundleType, entry) => {
89 switch (bundleType) {