Skip to content

fix(#4247): use useTransition to track mutation isMutating#4248

Open
SukkaW wants to merge 2 commits into
vercel:mainfrom
SukkaW:fix-mutate-state-in-transition
Open

fix(#4247): use useTransition to track mutation isMutating#4248
SukkaW wants to merge 2 commits into
vercel:mainfrom
SukkaW:fix-mutate-state-in-transition

Conversation

@SukkaW
Copy link
Copy Markdown

@SukkaW SukkaW commented Apr 24, 2026

When trigger is called within a transition (e.g. React's

action prop), any state update inside the transition (a.k.a. the trigger function) will be deferred/delayed until the transition finishes, which means the async function is resolved/rejected.

However, we don't want the isMutating update (false -> true -> false) to be deferred/delayed, otherwise the UI won't be able to reflect the loading state.

One way to do this is to use useTransition. In React 19, useTransition's isPending can be used to track async transition resolved/rejected state. And isPending would be an urgent update that won't be deferred/delayed.

React 18's useTransition doesn't support async function tracking. In React 16 and 17, there is no useTransition at all. A polyfill is introduced.

Alternative

Technically, we can use flushSync to force an urgent update, but it can be dangerous and may cause undefined behavior when invoked within a transition. It may even cause a Suspense boundary fallback to reappear, which is not ideal. Also, flushSync is a react-dom API.

Caveat

We lose the re-render optimization for isMutating. Now the component will always re-render when isPending/isMutaing changes no matter the component actually read isMutaing field or not.

@SukkaW SukkaW requested a review from shuding as a code owner April 24, 2026 16:39
@SukkaW SukkaW force-pushed the fix-mutate-state-in-transition branch from 6b2ecdf to 33a39a6 Compare April 24, 2026 16:41
@promer94 promer94 requested a review from huozhi as a code owner June 1, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants