Skip to content

Commit e08d892

Browse files
author
rohan4naik
committed
Clarify that server errors handled by Suspense are still reported
The 'Providing a fallback for server errors and client-only content' section stated React would not surface a server error when the client render succeeds. In practice React still reports it via onRecoverableError and logs recoverable error #419 to the console. Correct the wording and add a note about the opt-out caveat. Fixes #8497
1 parent 6be2b02 commit e08d892

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/content/reference/react/Suspense.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,7 @@ button {
23532353
23542354
If you use one of the [streaming server rendering APIs](/reference/react-dom/server) (or a framework that relies on them), React will also use your `<Suspense>` boundaries to handle errors on the server. If a component throws an error on the server, React will not abort the server render. Instead, it will find the closest `<Suspense>` component above it and include its fallback (such as a spinner) into the generated server HTML. The user will see a spinner at first.
23552355
2356-
On the client, React will attempt to render the same component again. If it errors on the client too, React will throw the error and display the closest [Error Boundary.](/reference/react/Component#static-getderivedstatefromerror) However, if it does not error on the client, React will not display the error to the user since the content was eventually displayed successfully.
2356+
On the client, React will attempt to render the same component again. If it errors on the client too, React will throw the error and display the closest [Error Boundary.](/reference/react/Component#static-getderivedstatefromerror) However, if it does not error on the client, React will not display the error in the UI, since the content was eventually displayed successfully. Note that the error thrown on the server is still reported: React calls the [`onRecoverableError`](/reference/react-dom/client/hydrateRoot#parameters) callback and logs a [recoverable error](/errors/419) to the console.
23572357
23582358
You can use this to opt out some components from rendering on the server. To do this, throw an error in the server environment and then wrap them in a `<Suspense>` boundary to replace their HTML with fallbacks:
23592359
@@ -2372,6 +2372,12 @@ function Chat() {
23722372
23732373
The server HTML will include the loading indicator. It will be replaced by the `Chat` component on the client.
23742374
2375+
<Note>
2376+
2377+
Even though the fallback is successfully replaced on the client, React still treats the error thrown on the server as a [recoverable error](/errors/419): it calls [`onRecoverableError`](/reference/react-dom/client/hydrateRoot#parameters) and logs the error to the console. There is no built-in way to mark an error as an intentional opt-out, so if you use this technique, throw a specific, recognizable error and filter it out in your `onRecoverableError` handler to avoid noise in your error reporting.
2378+
2379+
</Note>
2380+
23752381
---
23762382
23772383
### Waiting for a stylesheet to load {/*waiting-for-a-stylesheet-to-load*/}

0 commit comments

Comments
 (0)