Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stale default values in Next.js after submitting a form action #797

Open
ChristianIvicevic opened this issue Sep 29, 2024 · 2 comments
Open

Comments

@ChristianIvicevic
Copy link

Describe the bug and the expected behavior

After my server action has resolved and returned a successful response the form items are still showing the previous default values (reverting the newly entered values) despite me calling router.refresh() and fetching the latest data in the parent page and passing it down to the client component that renders the form.

To circumvent this issue I attempted to pass Date.now() as a key prop to my client component to force a full rerender which technically works, but it's noticeable that the form resets shortly to the previous default values and then updates with the new values.

Conform version

v1.2.2

Steps to Reproduce the Bug or Issue

  1. Clone this branch of my fork: https://github.com/ChristianIvicevic/conform/tree/nextjs-stale-defaults
  2. Open the Next.js example and go to the stale page
  3. See the current value read from the database file above the input and how it changes after submitting the form, but the field not updating accordingly

What browsers are you seeing the problem on?

Chrome, Safari

Screenshots or Videos

CleanShot.2024-09-30.at.00.30.54.mp4

Additional context

No response

@bbaterdene-gh
Copy link

bbaterdene-gh commented Nov 7, 2024

I managed to resolve my issue by using submission.reply() instead of returning an object. This approach ensures lastResult in the useForm hook stays updated as expected.

It might be helpful to adjust line 71 in examples/nextjs/app/actions.ts to use submission.reply().

@ChristianIvicevic
Copy link
Author

This issue has been fairly old, but in the last week I changed over to use submission.reply() and unfortunately that never worked as expected either.

Chances are that the new React 19 changes which reset forms on submit do contribute to that behavior as well. Once I find some time in the next few days or weeks I will look into an updated reproduction to contribute in order to see whether it's an issue with conform or my custom helper.

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

No branches or pull requests

2 participants