@samitouri / QOS-React-2 / commits / b300304710

Update error decoder URL (#27240)

Updates the error decoder to the URL for the new docs site. - Switches the domain from reactjs.org to react.dev - Switches to put the error code in the URL for SSG - All params are still in the query Example without args: - Before: `https://reactjs.org/docs/error-decoder.html?invariant=200` - After: ` https://react.dev/errors/200` Example with args: - Before: `https://reactjs.org/docs/error-decoder.html?invariant=124?args[]=foo&args[]=bar ` - After: ` https://react.dev/errors/124?args[]=foo&args[]=bar` Requires: https://github.com/reactjs/react.dev/pull/6214 --------- Co-authored-by: Jan Kassens <jkassens@meta.com>

Ricky committed Jan 17, 2024 at 21:41 UTC b3003047101b4c7a643788a8faf576f7e370fb45
4 files changed +12 -8
packages/shared/__tests__/ReactError-test.internal.js
+1 -1
@@ -41,7 +41,7 @@ describe('ReactError', () => {
41 it('should error with minified error code', () => {
42 expect(() => ReactDOM.render('Hi', null)).toThrowError(
43 'Minified React error #200; visit ' +
44 - 'https://reactjs.org/docs/error-decoder.html?invariant=200' +
44 + 'https://react.dev/errors/200' +
45 ' for the full message or use the non-minified dev environment' +
46 ' for full errors and additional helpful warnings.',
47 );
packages/shared/__tests__/ReactErrorProd-test.internal.js
+3 -3
@@ -19,21 +19,21 @@ describe('ReactErrorProd', () => {
19 it('should throw with the correct number of `%s`s in the URL', () => {
20 expect(formatProdErrorMessage(124, 'foo', 'bar')).toEqual(
21 'Minified React error #124; visit ' +
22 - 'https://reactjs.org/docs/error-decoder.html?invariant=124&args[]=foo&args[]=bar' +
22 + 'https://react.dev/errors/124?args[]=foo&args[]=bar' +
23 ' for the full message or use the non-minified dev environment' +
24 ' for full errors and additional helpful warnings.',
25 );
26
27 expect(formatProdErrorMessage(20)).toEqual(
28 'Minified React error #20; visit ' +
29 - 'https://reactjs.org/docs/error-decoder.html?invariant=20' +
29 + 'https://react.dev/errors/20' +
30 ' for the full message or use the non-minified dev environment' +
31 ' for full errors and additional helpful warnings.',
32 );
33
34 expect(formatProdErrorMessage(77, '<div>', '&?bar')).toEqual(
35 'Minified React error #77; visit ' +
36 - 'https://reactjs.org/docs/error-decoder.html?invariant=77&args[]=%3Cdiv%3E&args[]=%26%3Fbar' +
36 + 'https://react.dev/errors/77?args[]=%3Cdiv%3E&args[]=%26%3Fbar' +
37 ' for the full message or use the non-minified dev environment' +
38 ' for full errors and additional helpful warnings.',
39 );
packages/shared/formatProdErrorMessage.js
+7 -3
@@ -11,10 +11,14 @@
11 // during build.
12
13 function formatProdErrorMessage(code) {
14 - let url = 'https://reactjs.org/docs/error-decoder.html?invariant=' + code;
15 - for (let i = 1; i < arguments.length; i++) {
16 - url += '&args[]=' + encodeURIComponent(arguments[i]);
14 + let url = 'https://react.dev/errors/' + code;
15 + if (arguments.length > 1) {
16 + url += '?args[]=' + encodeURIComponent(arguments[1]);
17 + for (let i = 2; i < arguments.length; i++) {
18 + url += '&args[]=' + encodeURIComponent(arguments[i]);
19 + }
20 }
21 +
22 return (
23 `Minified React error #${code}; visit ${url} for the full message or ` +
24 'use the non-minified dev environment for full errors and additional ' +
scripts/jest/setupTests.js
+1 -1
@@ -169,7 +169,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
169 if (!message) {
170 return message;
171 }
172 - const re = /error-decoder.html\?invariant=(\d+)([^\s]*)/;
172 + const re = /react.dev\/errors\/(\d+)?\??([^\s]*)/;
173 const matches = message.match(re);
174 if (!matches || matches.length !== 3) {
175 return message;