From aa9f1e71d3264525dedffa36aeff49cbdae29f31 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Wed, 14 Feb 2024 19:42:49 -0500 Subject: [PATCH] Remove Error: prefix These don't really make sense to add to the message string since these prefixes are typically printed when the errors are printed anyway and are part of .stack. So prefixing just leads to duplicate prefixes. --- .../src/__tests__/ReactFlight-test.js | 22 +++++++++---------- .../src/__tests__/ReactFlightDOM-test.js | 4 +--- .../__tests__/ReactFlightDOMBrowser-test.js | 2 +- packages/react-server/src/ReactFizzServer.js | 4 ++-- .../react-server/src/ReactFlightServer.js | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js index f4a5929a2dd72..3bcedb6ec6c1c 100644 --- a/packages/react-client/src/__tests__/ReactFlight-test.js +++ b/packages/react-client/src/__tests__/ReactFlight-test.js @@ -799,12 +799,12 @@ describe('ReactFlight', () => { - +
- +
{
+ expectedMessage={'{message: "Short", extra: ..., nested: ...}'}>
{ />
- +
- +
- +
- +
} />
- +
- +
@@ -874,7 +872,7 @@ describe('ReactFlight', () => { } else if (typeof x === 'object' && x !== null) { return `digest({})`; } - return `digest(Error: ${String(x)})`; + return `digest(${String(x)})`; }, }); diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js index 91ba06dd329b9..465123f825500 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOM-test.js @@ -919,9 +919,7 @@ describe('ReactFlightDOM', () => { abort('for reasons'); }); if (__DEV__) { - expect(container.innerHTML).toBe( - '

Error: for reasons + a dev digest

', - ); + expect(container.innerHTML).toBe('

for reasons + a dev digest

'); } else { expect(container.innerHTML).toBe('

digest("for reasons")

'); } diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js index 2427317ce2c32..f8f3a1c3f2877 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js @@ -583,7 +583,7 @@ describe('ReactFlightDOMBrowser', () => { controller.abort('for reasons'); }); const expectedValue = __DEV__ - ? '

Error: for reasons + a dev digest

' + ? '

for reasons + a dev digest

' : '

digest("for reasons")

'; expect(container.innerHTML).toBe(expectedValue); diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index d4bb51211d672..e8ea394386df6 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -823,10 +823,10 @@ function encodeErrorForBoundary( // eslint-disable-next-line react-internal/safe-string-coercion message = String(error.message); } else if (typeof error === 'object' && error !== null) { - message = 'Error: ' + describeObjectForErrorMessage(error); + message = describeObjectForErrorMessage(error); } else { // eslint-disable-next-line react-internal/safe-string-coercion - message = 'Error: ' + String(error); + message = String(error); } boundary.errorMessage = message; diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 4c81931223e46..072a71b03dcc5 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -1678,10 +1678,10 @@ function emitErrorChunk( // eslint-disable-next-line react-internal/safe-string-coercion stack = String(error.stack); } else if (typeof error === 'object' && error !== null) { - message = 'Error: ' + describeObjectForErrorMessage(error); + message = describeObjectForErrorMessage(error); } else { // eslint-disable-next-line react-internal/safe-string-coercion - message = 'Error: ' + String(error); + message = String(error); } } catch (x) { message = 'An error occurred but serializing the error message failed.';