Skip to content

Clarify useActionState async non-transition warning #32207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/react-dom/src/__tests__/ReactDOMForm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,9 +1494,10 @@ describe('ReactDOMForm', () => {
await act(() => dispatch());
assertConsoleErrorDev([
[
'An async function was passed to useActionState, but it was dispatched outside of an action context. ' +
'This is likely not what you intended. ' +
'Either pass the dispatch function to an `action` prop, or dispatch manually inside `startTransition`',
'An async function with useActionState was called outside of a transition. ' +
'This is likely not what you intended (for example, isPending will not update ' +
'correctly). Either call the returned function inside startTransition, or pass it ' +
'to an `action` or `formAction` prop.',
{withoutStack: true},
],
]);
Expand Down
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2231,10 +2231,10 @@ function handleActionReturnValue<S, P>(
if (__DEV__) {
if (!node.isTransition) {
console.error(
'An async function was passed to useActionState, but it was ' +
'dispatched outside of an action context. This is likely not ' +
'what you intended. Either pass the dispatch function to an ' +
'`action` prop, or dispatch manually inside `startTransition`',
'An async function with useActionState was called outside of a transition. ' +
'This is likely not what you intended (for example, isPending will not update ' +
'correctly). Either call the returned function inside startTransition, or pass it ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dispatch manually" vs new "call the returned function" is much clearer 👍🏻

'to an `action` or `formAction` prop.',
);
}
}
Expand Down
Loading