Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error decoder URL #27240

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/shared/__tests__/ReactError-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/__tests__/ReactErrorProd-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);
Expand Down
10 changes: 7 additions & 3 deletions packages/shared/formatProdErrorMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
rickhanlonii marked this conversation as resolved.
Show resolved Hide resolved
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 ' +
Expand Down
2 changes: 1 addition & 1 deletion scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down