Closed haines closed 3 months ago
This is interesting. It's a little bit related to #117. Like you said, it's because of the async submit.
When I implement this pattern, I usually leave the modal present in the dom and show my loading state on the modal button instead of closing the modal. But both patterns should be considered valid, I think.
I believe useSubmit
and fetcher.submit
can both accept FormData
directly instead of an element, so maybe the solution is to submit the data that we validated rather than the submitter or form elements. I'm not sure if this would miss some edge-cases that can only be handled by submitting the elements though. It could theoretically open us up to behavior that doesn't match the native / no-js behavior.
I think that sounds like a good approach. It's unfortunate that React Router doesn't export getFormSubmissionInfo
since that seems to handle the edge cases.
Could you test this again with v5? I updated when we capture the form data to avoid weird race conditions caused by the async submit. So this might be fixed now.
Which packages are impacted?
remix-validated-form
@remix-validated-form/with-zod
@remix-validated-form/with-yup
zod-form-data
What version of these packages are you using?
Please provide a link to a minimal reproduction of the issue.
https://github.com/haines/remix-validated-form-submit-from-modal-repro
Steps to Reproduce the Bug or Issue
When a
ValidatedForm
is submitted by a button in a modal that is unmounted from the DOM on submit, it fails with an uncaught error. The same problem does not exist in Remix's standardForm
.git clone https://github.com/haines/remix-validated-form-submit-from-modal-repro.git
cd remix-validated-form-submit-from-modal-repro
npm install
npm run dev
Expected behavior
ValidatedForm
behaves the same as Remix's standardForm
.Screenshots or Videos
No response
Platform
Additional context
I guess this may be due to async submit. When Remix's
Form
calls React Router'ssubmit
hook, thesubmitter
(the button element) hasform
set (because the button hasn't been removed from the DOM yet?). WhenValidatedForm
callssubmit
, thesubmitter
'sform
property isnull
.