facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.86k stars 47.06k forks source link

[React 19] No re-render after 'useActionState' action queue finishes #30691

Open morditore opened 3 months ago

morditore commented 3 months ago

Summary

When multiple client side actions are scheduled via useActionState, the "Action queue" promises are processed sequentially as expected. However after the last action promise resolves, the component is not re-rendered. This means, the component is stuck in "loading" without access to "data".

Steps to reproduce

  1. Open the demo here: https://codesandbox.io/p/sandbox/use-action-state-stuck-xl72xk?file=%2Fsrc%2FApp.js
  2. Click the "Send request" button two times.
  3. After 10 seconds (each request is 5 seconds and processed sequentially), the component still shows "Loading..." and not the dummy data (as I would expect).

Notes

Is this behavior intentional?

eps1lon commented 3 months ago

Can confirm. We do have tests covering those scenarios which pass oddly enough. I wasn't able to repro with real timers either in Jest.

lxmarinkovic commented 2 months ago

@morditore and @eps1lon here is a demo of bugfix: https://codesandbox.io/p/sandbox/use-action-state-stuck-forked-2y355f?workspaceId=cb6f0dff-d403-475d-ab82-61ee18a4ad69

it required an edit of ReactHooks.js #31001 The demo is used a simplified standalone version of ReactHooks.js that you can work in CodeSandbox without relying on internal React modules :D