|
7 | 7 | * @flow |
8 | 8 | */ |
9 | 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 | + |
10 | 14 | /** |
11 | 15 | * WARNING: DO NOT manually require this module. |
12 | 16 | * This is a replacement for `invariant(...)` used by the error code system |
|
15 | 19 | */ |
16 | 20 | function reactProdInvariant(code: string): void { |
17 | 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; |
26 | 23 | for (let argIdx = 0; argIdx < argCount; argIdx++) { |
27 | | - message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]); |
| 24 | + url += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]); |
28 | 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 | + ); |
42 | 41 | } |
43 | 42 |
|
44 | 43 | export default reactProdInvariant; |
0 commit comments