Skip to content

Commit 8dfb057

Browse files
authored
Unfork invariant and instead use it from reactProdInvariant (#12585)
1 parent 76b4ba0 commit 8dfb057

File tree

3 files changed

+21
-71
lines changed

3 files changed

+21
-71
lines changed

packages/shared/forks/reactProdInvariant.www.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

packages/shared/reactProdInvariant.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* @flow
88
*/
99

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+
1014
/**
1115
* WARNING: DO NOT manually require this module.
1216
* This is a replacement for `invariant(...)` used by the error code system
@@ -15,30 +19,25 @@
1519
*/
1620
function reactProdInvariant(code: string): void {
1721
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;
2623
for (let argIdx = 0; argIdx < argCount; argIdx++) {
27-
message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
24+
url += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]);
2825
}
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+
);
4241
}
4342

4443
export default reactProdInvariant;

scripts/rollup/forks.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ const forks = Object.freeze({
8484
}
8585
},
8686

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-
9887
// Different dialogs for caught errors.
9988
'react-reconciler/src/ReactFiberErrorDialog': (bundleType, entry) => {
10089
switch (bundleType) {

0 commit comments

Comments
 (0)