Open jatwood opened 4 months ago
Basically, if you want it to show status as not-pending once counter is updated then create another state variable(lets say pendinggg) whose initial value is same as that of pending and you immediately have to set pendinggg as false once counter is updated and inside useeffect have a condition that once pending is false then not to re-run the useeffect.
import React, { useState, useEffect } from 'react'; const useFormStatus = () => { return { pending: true }; // Example status, replace with actual implementation }; function SubmissionStateBody({pending}) { const [counter, setCounter] = useState(0); const [localPending, setLocalPending] = useState(pending); useEffect(() => { let id; if (localPending) { id = setTimeout(() => { setCounter((prevCounter) => prevCounter + 1); setLocalPending(false); // Stop showing pending as soon as the counter updates }, 1000); } else { setCounter(0); }
return () => clearTimeout(id);
}, [localPending, counter]);
return
Pending for ${counter} seconds
: 'Not pending'}export default function SubmissionStateCorrect() {
const formStatus = useFormStatus();
return
thats the code
here once counter updates, status becomes not pending..
@Aman37773 This issue is about a buguseFormStatus
which is a hook in react-dom.
Can be reproduced with latest RC and just Client Actions: https://codesandbox.io/p/sandbox/react-useformstatus-pending-reset-on-unrelated-state-update-m59zw8
@eps1lon I would like to pick this bug, can you please assign it to me?
@ujshaikh We don't assign people to issues since they might stop working on the issue and then it looks like the issue is still being worked on. Assigning issues hasn't helped us manage issues. We just recommend to people start working on a bug immediately.
Any news on this topic? I recently started using React 19 RC as part of the upgrade of Next.js to v15 and I'm facing this issue in most places where I'm using useFormStatus
. If we don't get a fix for this issue I'll have to think of getting rid of useFormStatus
and replace it with a custom solution.
If you have a component that relies on the
pending
return value ofuseFormStatus
, thepending
state will incorrectly reset tofalse
if the component is updated due to auseState
update. This does not happen if theuseState
hook is placed in a child component.React version: 19.0.0-rc-512b09b2-20240718
Steps To Reproduce
codesandbox.io/p/sandbox/react-useformstatus-pending-reset-on-unrelated-state-update-m59zw8
useFormStatus().pending
. Have the component also use auseState
hook that updates on an interval usinguseEffect
.<form />
elementuseFormStatus().pending
is reset to false as soon as a call tosetState
happnsExample component
this example works as expected,
useFormStatus().pending
state matches the server actions stateLink to code example:
Github repro using nextjs starter template
The current behavior
The UI shows the submission as pending for the length of the server action.
The expected behavior
The UI shows the submission as not-pending as soon as the counter is updated.