-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix(remix-react): prevent form data loss by appending submitter's value in useSubmit
(<Form>
)
#3611
fix(remix-react): prevent form data loss by appending submitter's value in useSubmit
(<Form>
)
#3611
Conversation
Currently, remix-react's `<Form>` through `useSubmit` (`useSubmitImpl`) implementation, includes the submitter value by setting it on the `formData`. Unfortunetly, this may override any existing inputs having the same name than the submitter; resulting in data loss. Instead, the submitter's value should be appended to the `formData`.
May somebody point me to a doc/thread or let me know what I can expect for the review process? (cc @MichaelDeBoey ?) It seems this PR has been "seen", but not reviewed. CI hasn't been ran though... And unfortunately nobody seems to be assigned for reviews. If that's encouraged I can specifically mention maintainers which would seem most appropriate for review by looking at the git history. I've also opened another PR #3613 fixing issues also touching the I'd be eager to help, both fixes are imho quite pertinent for the |
integration/hook-useSubmit-test.ts
Outdated
|
||
export default function Index() { | ||
let submit = useSubmit(); | ||
let handleClick = event => submit(nativeEvent.submitter || e.currentTarget) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does nativeEvent
come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oups, thanks. I've fixed that. The test was passing because the <form>
was natively submitting with the GET method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended again to call event.preventDefault()
to only have the behavior of submit()
being tested (not native form submit). I've double-checked that test and it now test what it meant to.
|
Hooray! It failed :) |
Looking into this further, this is a behavioral change that I think @ryanflorence will want to look at. I'll let him know. |
09cca9d
to
0b88212
Compare
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
When submitting a form the submitter's value must be appended to the `formData` and not have it's value "set" or pre-existing data under the same name may be overidden resulting in data loss. This commit fixes the `useSubmit() hook (`useSubmitImpl`) and consequently it's indirect usage through the `<Form>` component.
0b88212
to
8a81f7b
Compare
@kentcdodds, @ryanflorence – any chance to have a follow up on this? To be honest I don't think this really represent a behavioral change. IMHO the current implementation is the one deviating from what would be the expected behavior. I'd also say a bug which broke normal behavior. |
I agree, if Remix deviates from default browser behavior, then it's a bug, and this PR resolves it. I would be surprised if anyone is dependent on the buggy behavior. I think it would be rare to see somebody using the same name in a button as for an existing input. But since the browser support this, I am +1 on the fix. |
…ue in `useSubmit` (`<Form>`) (#3611) * test: failing test with submitter value not appended to form data Currently, remix-react's `<Form>` through `useSubmit` (`useSubmitImpl`) implementation, includes the submitter value by setting it on the `formData`. Unfortunetly, this may override any existing inputs having the same name than the submitter; resulting in data loss. Instead, the submitter's value should be appended to the `formData`. * fix(remix-react): prevent form data loss by appending submitter's value When submitting a form the submitter's value must be appended to the `formData` and not have it's value "set" or pre-existing data under the same name may be overidden resulting in data loss. This commit fixes the `useSubmit() hook (`useSubmitImpl`) and consequently it's indirect usage through the `<Form>` component.
Closes: (the following issue)
DocsN/ATesting Strategy:
See integration Bug-Report-Test via commit: 4187030
test: failing test with submitter value not appended to form data
4187030 <Nicholas Rakoto> Wed, 29 Jun 2022 22:30:59 +0200
fix(remix-react): prevent form data loss by appending submitter's value
2a70250 <Nicholas Rakoto> Wed, 29 Jun 2022 22:34:39 +0200