Open
Description
Summary
The example action code in startTransition
needs another startTransition
in order to handle the await
per this limitation.
Page
https://react.dev/reference/rsc/server-functions#server-functions-with-actions
Details
set
functions following await
inside startTransition
need to be wrapped in another startTransition
to be handled correctly.
Current
startTransition(async () => {
const {error} = await updateName(name);
// TODO: wrap `set` functions in another `startTransition`
if (!error) {
setError(error);
} else {
setName('');
}
})
Fixed
startTransition(async () => {
const {error} = await updateName(name);
startTransition(() => {
if (!error) {
setError(error);
} else {
setName('');
}
})
})
Admittedly, this may make the example less clear. As an alternative, maybe include a mention of the correct way to use await
and marking subsequent state updates as Transitions.