Skip to content

Call async action listeners that are attached after the action settles - #38446

Open
CinchBlue wants to merge 1 commit into
react:mainfrom
CinchBlue:fix-async-action-late-listener
Open

CinchBlue wants to merge 1 commit into
react:mainfrom
CinchBlue:fix-async-action-late-listener

Conversation

@CinchBlue

Copy link
Copy Markdown

Summary

Fixes #38431.

If an async action settles after a render that suspended on it, but before that render commits, the Suspense fallback
stays on screen even though nothing is pending.

The thenables in ReactFiberAsyncAction.js (entangleAsyncAction and chainThenableValue) only push to a listener
array in then. The Suspense retry listener is attached at commit. If the action has already settled by then, the
array has already been drained, so the listener is never called. useTransition state goes through
chainThenableValue, so it is affected too.

With this change, calling then on a thenable that has already settled schedules the listener instead of dropping it.
It uses a microtask, or an immediate Scheduler task in hosts without microtasks.

How did you test this change?

Added packages/react-reconciler/src/__tests__/ReactAsyncActionLateListener-test.js with two tests. The first is the
fallback case. The second covers useTransition state, which goes through chainThenableValue.

yarn test --maxWorkers=2 -r=stable ReactAsyncActionLateListener
yarn test --maxWorkers=2 -r=stable --prod ReactAsyncActionLateListener
yarn test --maxWorkers=2 -r=experimental ReactAsyncActionLateListener
yarn test --maxWorkers=2 -r=experimental --prod ReactAsyncActionLateListener
yarn test --maxWorkers=2 ReactAsyncActions

Both new tests pass in all four configs with the change. With only ReactFiberAsyncAction.js reverted, both fail in
all four. The existing ReactAsyncActions-test.js passes 26/26. yarn prettier made no changes, and yarn linc and
yarn flow dom-node both pass. I did not run the full yarn test or the www/xplat flow targets.

The thenables built in ReactFiberAsyncAction.js (entangleAsyncAction and
chainThenableValue) only pushed to a listener array in `then`. A Suspense
retry listener is attached at commit. If the action settled between the
render that suspended and that commit, the array had already been drained,
so the listener was never called and the fallback stayed on screen with
nothing pending. useTransition state goes through chainThenableValue.

When `then` is called on an already-settled thenable, schedule the listener
instead of dropping it: a microtask, or an immediate Scheduler task in hosts
without microtasks. Adds two tests that fail without the change.

Fixes react#38431

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@meta-cla meta-cla Bot added the CLA Signed label Nov 29, 2026
@github-actions

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against 19aefae

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Suspense fallback stays forever when an async action settles before the fallback commits

1 participant