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 <[email protected]>
This commit is contained in:
Ricky
2024-01-17 21:41:07 -05:00
committed by GitHub
co-authored by Jan Kassens
parent b22798cec1
commit a08b2ed78e
4 changed files with 12 additions and 8 deletions
@@ -41,7 +41,7 @@ describe('ReactError', () => {
it('should error with minified error code', () => {
expect(() => ReactDOM.render('Hi', null)).toThrowError(
'Minified React error #200; visit ' +
'https://reactjs.org/docs/error-decoder.html?invariant=200' +
'https://react.dev/errors/200' +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
@@ -19,21 +19,21 @@ describe('ReactErrorProd', () => {
it('should throw with the correct number of `%s`s in the URL', () => {
expect(formatProdErrorMessage(124, 'foo', 'bar')).toEqual(
'Minified React error #124; visit ' +
'https://reactjs.org/docs/error-decoder.html?invariant=124&args[]=foo&args[]=bar' +
'https://react.dev/errors/124?args[]=foo&args[]=bar' +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
expect(formatProdErrorMessage(20)).toEqual(
'Minified React error #20; visit ' +
'https://reactjs.org/docs/error-decoder.html?invariant=20' +
'https://react.dev/errors/20' +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
expect(formatProdErrorMessage(77, '<div>', '&?bar')).toEqual(
'Minified React error #77; visit ' +
'https://reactjs.org/docs/error-decoder.html?invariant=77&args[]=%3Cdiv%3E&args[]=%26%3Fbar' +
'https://react.dev/errors/77?args[]=%3Cdiv%3E&args[]=%26%3Fbar' +
' for the full message or use the non-minified dev environment' +
' for full errors and additional helpful warnings.',
);
+7 -3
View File
@@ -11,10 +11,14 @@
// during build.
function formatProdErrorMessage(code) {
let url = 'https://reactjs.org/docs/error-decoder.html?invariant=' + code;
for (let i = 1; i < arguments.length; i++) {
url += '&args[]=' + encodeURIComponent(arguments[i]);
let url = 'https://react.dev/errors/' + code;
if (arguments.length > 1) {
url += '?args[]=' + encodeURIComponent(arguments[1]);
for (let i = 2; i < arguments.length; i++) {
url += '&args[]=' + encodeURIComponent(arguments[i]);
}
}
return (
`Minified React error #${code}; visit ${url} for the full message or ` +
'use the non-minified dev environment for full errors and additional ' +
+1 -1
View File
@@ -169,7 +169,7 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
if (!message) {
return message;
}
const re = /error-decoder.html\?invariant=(\d+)([^\s]*)/;
const re = /react.dev\/errors\/(\d+)?\??([^\s]*)/;
const matches = message.match(re);
if (!matches || matches.length !== 3) {
return message;