Question

Cursor keeps rewriting my whole form component instead of fixing the bug

Solved · 86 viewsasked by tomvibes

I have a form component that submits twice when you press Enter. Every time I ask Cursor to fix it, it rewrites the whole SubmitForm.tsx, changes the styling, and the double submit is still there. I'm on round six.

One press on Enter in the email field gives this:

What I’ve tried
  1. Asked it to "only fix the double submit, don't touch anything else" (it still rewrote the file)
  2. Started a new chat and pasted only the component
  3. Reverted to the git version from before it started
Comment

2 answers

Marked as helpful by the asker
dev_ana

The bug is almost certainly two submit paths: a <button type="submit"> inside a <form onSubmit> and an onKeyDown handler that calls submit on Enter. Enter triggers both.

Remove the key handler, the form already submits on Enter:

<form onSubmit={handleSubmit}>
  <input name="email" />
  <button type="submit">Save</button>
</form>

For the Cursor loop: select only the onKeyDown lines and ask "why does this fire together with onSubmit?" A question about cause gets a smaller answer than "fix this".

Comment
There it was: an onKeyDown on the email input that called handleSubmit on Enter. Deleted it, one POST now and the warning is gone too. tomvibes
The warning came from the same double call, the second submit set parent state mid-render. Two bugs, one line. dev_ana
felix_codes

Tip for next time: add // do not rewrite this file, only edit the lines I select at the top while you're debugging. Sounds silly, works surprisingly often.

Comment
Ha, adding that comment for the next bug. Cursor did keep its hands off the file when I only selected the handler. tomvibes