Question

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

Solved · 36 views · asked by tomvibes · edited

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.

POST /api/orders 201
POST /api/orders 201
Warning: Cannot update a component while rendering a different component
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

3 answers

Marked as helpful by the asker
dev_ana · edited

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
felix_codes · edited

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