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

Remix clientAction breaks on form reset #516

Open
edmundhung opened this issue Mar 14, 2024 Discussed in #476 · 0 comments
Open

Remix clientAction breaks on form reset #516

edmundhung opened this issue Mar 14, 2024 Discussed in #476 · 0 comments
Labels
bug Something isn't working

Comments

@edmundhung
Copy link
Owner

Discussed in #476

Originally posted by QzCurious February 21, 2024

Describe the bug and the expected behavior

Submitting a conform driven <Form /> by "press Enter on input" should not make a real POST submission to server. It should behave the same as clicking a submit button.

Quick comparison:

Submit by click submit button Submit by press Enter
<Form /> Acts the same as others
bandicam.2024-02-23.17-38-15-684.mp4
Acts the same as others
bandicam.2024-02-23.17-39-02-273.mp4
<Form /> with conform Acts the same as others
bandicam.2024-02-23.17-50-41-381.mp4
Bug: It acts the same as others AND make a real POST submission to server
bandicam.2024-02-23.17-51-57-065.mp4

I've tried hard to make a very minimum reproduction to reveal root cause. I believe the bug is occurring with all of these conditions are met:

  • clientAction reply with { resetForm: true }
    export const clientAction = async ({ request }: ClientActionFunctionArgs) => {
      const formData = await request.formData();
      const submission = parseWithZod(formData, { schema });
      return submission.reply({ resetForm: true });
    };
  • useForm with lastResult (of cause) AND shouldValidate being "onBlur"
    const [form, fields] = useForm({
      shouldValidate: "onBlur",
      lastResult,
    });

Apply one of the following changes workaround the bug:

  • Submitting the <Form /> by submit button works fine
  • submission.reply(), that is, without { resetForm: true }
  • Use action instead of clientAction (But I want a SPA app)
  • shouldValidate being onInput or onSubmit

Conform version

v1.0.2

Steps to Reproduce the Bug or Issue

  1. git clone https://github.com/QzCurious/conform-remix-vite-form-submission-bug
  2. It's a Remix Vite App
  3. pnpm i
  4. pnpm dev and open the web page
  5. Focus on "remix <Form /> with conform" and press Enter
  6. Bug happens: <Form /> is handled by clientAction, AND it make a real POST submission to server.

What browsers are you seeing the problem on?

No response

Screenshots or Videos

Screen.Recording.2024-02-22.at.12.16.31.AM.mov

Additional context

Remix with Vite were just marked stable today.

@edmundhung edmundhung added the bug Something isn't working label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant