Skip to content

Commit 8efce78

Browse files
Clarify error handling for standalone startTransition (#8648)
* Clarify standalone startTransition error handling * Polish startTransition error handling docs * Describe startTransition differences neutrally * Clarify startTransition callback wording * Remove repeated startTransition caveat * Preserve existing startTransition guidance * Preserve useTransition error guidance * Update src/content/reference/react/useTransition.md Co-authored-by: Sebastian "Sebbie" Silbermann <silbermann.sebastian@gmail.com> * Clarify standalone startTransition error reporting --------- Co-authored-by: Sebastian "Sebbie" Silbermann <silbermann.sebastian@gmail.com>
1 parent fde7662 commit 8efce78

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/content/reference/react/startTransition.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ With a Transition, your UI stays responsive in the middle of a re-render. For ex
9292

9393
<Note>
9494

95-
`startTransition` is very similar to [`useTransition`](/reference/react/useTransition), except that it does not provide the `isPending` flag to track whether a Transition is ongoing. You can call `startTransition` when `useTransition` is not available. For example, `startTransition` works outside components, such as from a data library.
95+
`startTransition` is very similar to [`useTransition`](/reference/react/useTransition), except that it does not provide the `isPending` flag to track whether a Transition is ongoing. The standalone function is also not associated with a component, so if the function passed to it throws an error or returns a rejected Promise, React reports the error with [`reportError`](https://developer.mozilla.org/en-US/docs/Web/API/Window/reportError). You can call `startTransition` when `useTransition` is not available. For example, `startTransition` works outside components, such as from a data library.
9696

9797
[Learn about Transitions and see examples on the `useTransition` page.](/reference/react/useTransition)
9898

src/content/reference/react/useTransition.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ main {
15671567
15681568
### Displaying an error to users with an error boundary {/*displaying-an-error-to-users-with-error-boundary*/}
15691569
1570-
If a function passed to `startTransition` throws an error, you can display an error to your user with an [error boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary). To use an error boundary, wrap the component where you are calling the `useTransition` in an error boundary. Once the function passed to `startTransition` errors, the fallback for the error boundary will be displayed.
1570+
If a function passed to `startTransition` throws an error or returns a rejected Promise, you can display an error to your user with an [error boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary). To use an error boundary, wrap the component where you are calling the `useTransition` in an error boundary. Once the function passed to `startTransition` errors, the fallback for the error boundary will be displayed.
15711571
15721572
<Sandpack>
15731573
@@ -1738,7 +1738,11 @@ This is a JavaScript limitation due to React losing the scope of the async conte
17381738
17391739
### I want to call `useTransition` from outside a component {/*i-want-to-call-usetransition-from-outside-a-component*/}
17401740
1741-
You can't call `useTransition` outside a component because it's a Hook. In this case, use the standalone [`startTransition`](/reference/react/startTransition) method instead. It works the same way, but it doesn't provide the `isPending` indicator.
1741+
You can't call `useTransition` outside a component because it's a Hook. In this
1742+
case, the standalone [`startTransition`](/reference/react/startTransition)
1743+
function can mark state updates as Transitions. It does not provide the
1744+
`isPending` flag. Because the standalone function is not associated with a
1745+
component, an Error Boundary cannot handle errors from its Transition.
17421746
17431747
---
17441748

0 commit comments

Comments
 (0)