react icon indicating copy to clipboard operation
react copied to clipboard

Bug: pending attribute from useFormStatus is stuck as "true" when form action takes longer than ~5s to resolve

Open Veath opened this issue 1 year ago • 6 comments

React version: canary

Steps To Reproduce

  1. open example link-This is a demo example from the official website, only the settimeout time has been changed.(form action resolve promise after 10 seconds)
  2. click submit button
  3. see the button text

Link to code example: https://codesandbox.io/s/useformstatus-vzn8tm?file=/App.js:129-142

The current behavior

The button triggers the form action, and the pending useFormStatus is always true, even if the action is completed.

The expected behavior

The button triggers the form action. After the action is executed, useFormStatus should change from pending-true to pending-false.

Debug found that when the code is executed here-renderRootSync, throwValue has actually been resolved. If throwAndUnwindWorkLoop adds a then callback after resolved, it will not be triggered. image

If you change the settimeout timer in the form action to a smaller value, such as 1000ms, then the code will go here renderRootConcurrent, and replaySuspendedUnitOfWork can start to re-render. image

Veath avatar Oct 31 '23 02:10 Veath

Thanks for the bug report, I've reproduced the bug in a simpler codesandbox. It looks like right around 5s for a client action is the point when the pending property gets stuck and isn't updated: https://codesandbox.io/s/useformstatus-forked-vsdskv?file=/App.js

@acdlite can you take a look?

mattcarrollcode avatar Nov 06 '23 21:11 mattcarrollcode

output

I updated the CodeSandbox to highlight that issue occurs with a client action that takes 5s but not a action that takes 4s. Its on the experimental channel. In my experimentation it occurs somewhere between 4900ms and 5000ms: https://codesandbox.io/s/useformstatus-forked-vsdskv?file=/App.js

mattcarrollcode avatar Nov 07 '23 21:11 mattcarrollcode

https://codesandbox.io/p/sandbox/competent-chatelet-8qvvnm?file=%2Fapp%2Fpage.tsx%3A3%2C43

I have an interesting observation (I'm not sure if it's the same bug but it seems related) with useFormStatus and server actions:

  • If a component only has the useFormStatus hook, it works correctly
  • If the component also has an useEffect hook, it does not work. The pending status changes to false almost inmediately

Santiago-j-s avatar Nov 08 '23 22:11 Santiago-j-s

I'm facing same issues:

  • After triggering the action and pending goes to true, If the component is re-rendered after updating the state the pending status switch to false.
  • Pending stuck as true for long taking actions

This is stopping me to use this on production. Please we need some fix asap. Thanks!

dev2xl avatar Jan 20 '24 15:01 dev2xl

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Apr 19 '24 16:04 github-actions[bot]

This no longer reproduces on the latest Canary: https://codesandbox.io/p/sandbox/goofy-pasteur-268ly3

@dev2xl @Veath Could you confirm that you're also not seeing this issue in your apps anymore?

eps1lon avatar Apr 19 '24 16:04 eps1lon

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Jul 18 '24 17:07 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Jul 25 '24 17:07 github-actions[bot]