form icon indicating copy to clipboard operation
form copied to clipboard

First input change after failed submit ignored with Next server actions

Open evaogbe opened this issue 6 months ago • 2 comments

Describe the bug

In a form using Next server actions and validation after submitting an invalid input, the next character typed into the input is not shown. The input only shows from the second character on

Your minimal, reproducible example

https://stackblitz.com/edit/nextjs-dbp2u3qq?file=app%2Fexample-form.tsx

Steps to reproduce

  1. Press submit button
  2. Type a character into the input

Expected behavior

The first character typed should be seen in the input

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Chrome and Firefox

TanStack Form adapter

react-form

TanStack Form version

1.12.2

TypeScript version

5.2.2 and 5.8.3

Additional context

No response

evaogbe avatar Jun 10 '25 12:06 evaogbe

This is happening with the remix form as well. https://stackblitz.com/github/tanstack/form/tree/main/examples/react/remix?embed=1&theme=light&preset=node&file=src/index.tsx

Sushant-Borsania avatar Jun 11 '25 06:06 Sushant-Borsania

Looking at the other issue mentioned regarding the similar issue, I believe this may help short term:

const form = useForm({
    ...formOpts,
    transform: useTransform(
      (baseForm) => {
        if (!actionData) return baseForm;
        const { values, ...serverState } = actionData;
        return mergeForm(baseForm, serverState);
      },
      [actionData]
    ),
  });

Sushant-Borsania avatar Jun 11 '25 07:06 Sushant-Borsania