@samitouri / QOS-React-2 / commits / 76b4ba0129

Preserve error codes for invariants on www (#12539)

* Preserve error codes for invariants on www * Remove unintentional change

Dan Abramov committed Apr 9, 2018 at 18:57 UTC 76b4ba01290f446f4313adf3846954412c6051b8
5 files changed +62
packages/shared/forks/reactProdInvariant.www.js new
+38
@@ -0,0 +1,38 @@
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
+3
@@ -31,6 +31,9 @@ function reactProdInvariant(code: string): void {
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
scripts/rollup/build.js
+8
@@ -82,6 +82,14 @@ function getBabelConfig(updateBabelOptions, bundleType, filename) {
82 switch (bundleType) {
83 case FB_DEV:
84 case FB_PROD:
85 + return Object.assign({}, options, {
86 + plugins: options.plugins.concat([
87 + // Minify invariant messages
88 + require('../error-codes/replace-invariant-error-codes'),
89 + // Wrap warning() calls in a __DEV__ check so they are stripped from production.
90 + require('../babel/wrap-warning-with-env-check'),
91 + ]),
92 + });
93 case RN_DEV:
94 case RN_PROD:
95 return Object.assign({}, options, {
scripts/rollup/forks.js
+11
@@ -84,6 +84,17 @@ 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 +
98 // Different dialogs for caught errors.
99 'react-reconciler/src/ReactFiberErrorDialog': (bundleType, entry) => {
100 switch (bundleType) {
scripts/rollup/wrappers.js
+2
@@ -94,6 +94,7 @@ ${license}
94 *
95 * @noflow
96 * @preventMunge
97 + * @preserve-invariant-messages
98 */
99
100 'use strict';
@@ -112,6 +113,7 @@ ${license}
113 *
114 * @noflow
115 * @preventMunge
116 + * @preserve-invariant-messages
117 */
118
119 ${source}`;