Skip to content

Commit

Permalink
Simplify abort error handling
Browse files Browse the repository at this point in the history
The way dev generates errors from the hash, message, and stack parts we can use errorHash like a message if we do not also send a message. This means we can unify the implementation for both dev and prod and get the expected outcomes on the client regardless of which mode they are running in.

I noticed this because there was an edge case before where if you ran the server in dev mode and the client in prod mode you would not see this error message at all.
  • Loading branch information
gnoff committed May 18, 2022
1 parent 760c53a commit 036afda
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/react-server/src/ReactFizzServer.js
Expand Up @@ -1492,16 +1492,9 @@ function abortTask(task: Task): void {

if (!boundary.forceClientRender) {
boundary.forceClientRender = true;
if (__DEV__) {
// In DEV error messages are sent to the client and since this is not being handled
// by onError there is no error hash to send.
boundary.errorMessage =
'This Suspense boundary was aborted by the server';
} else {
// In Prod only error hashes are sent to the client. Even though this is not a hash
// it will get bubbled up to the user the way we expect it to which is why it goes here
boundary.errorHash = 'This Suspense boundary was aborted by the server';
}
// Technically not a hash since there is no error to pass to onError. However it will be handled
// the way we want in both dev and prod modes on the client if we report it here as a hash
boundary.errorHash = 'This Suspense boundary was aborted by the server';
if (boundary.parentFlushed) {
request.clientRenderedBoundaries.push(boundary);
}
Expand Down

0 comments on commit 036afda

Please sign in to comment.