Repository navigation
feat: defaultSubmitHandler, submitRawValues, resetOnSuccess and 5 issue fixes - #186
Merged
Merged
Conversation
createFormData sent each file of a FileList or file array under the plain key. With one file there is only one entry, so generateFormData parsed it as a single File and not as [File]. A single file now gets a "[]" key. A key that already ends with "[]" does not get a second suffix. Closes #178
Features: - defaultSubmitHandler on the hook return. A custom onValid can call it to submit in the default way. The form action, method and encType of the last handleSubmit call still apply (#148). - submitRawValues option: the default submit handler sends getValues() and not the resolver output (#172). - resetOnSuccess option: reset the form after a submission when the action returns no errors (#157). Fixes: - Derive the return types of useRemixForm and useRemixFormContext from UseFormReturn. The built .d.ts listed the members of react-hook-form 7.75, so getErrors and resetDefaultValues were missing for users of newer versions (#185). - Read action, method and enctype with the HTMLFormElement getters. An input with one of these names replaced the form property (#139). - Remove a trailing slash from the basename before it is removed from the action, so the action keeps its leading "/" (#175). - Add a regression test that clearErrors removes server errors (#12).
commit: |
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds three opt-in submit features to
useRemixFormand fixes five reported bugs. The changeset isminor, so the merge makes the Release PR for 7.3.0.defaultSubmitHandler(Expose default submit handler #148),submitRawValues(Incorrect serialization of zod objects with complex types (transform, refine,...) #172) andresetOnSuccess(Automatically reset form on valid submission / loader revalidation #157).action,methodorenctype(Fieldmethodin values causes form to fail submission #139), abasenamewith a trailing slash (Form submission triggers client-side navigation when basename is set #175), and one file in an array (Arrays of files orFileListobjects with only one element in them are not parsed as arrays #178).clearErrors(Cannot clear custom errors when returned by the server #12). This PR adds a regression test.Description
Features
defaultSubmitHandleron the hook return is the handler that runs whensubmitHandlers.onValidis not set. A customonValidcan do its own work and then call it. The form action, method and encType of the lasthandleSubmitcall still apply, so you do not have to pass them through.submitRawValues: truemakes the default handler sendgetValues()instead of the resolver output. A zod.transform()then runs only on the server.resetOnSuccess: trueresets the form when the submission ends and the action returned noerrors.Fixes
.d.tslisted the members of react-hook-form 7.75 one by one. Users with 7.82 and later gotmissing getErrors, resetDefaultValueson<RemixFormProvider {...form}>. The return types ofuseRemixFormanduseRemixFormContextnow come fromUseFormReturn. This probably also fixes TypeError with the control object #116, but I could not reproduce that report.methodin values causes form to fail submission #139: in a browser,form.methodreturns an<input name="method">if the form has one. The hook now readsaction,methodandenctypewith theHTMLFormElementgetters./app/, the hook removed/app/from the action and leftjoin, which is a relative path. It now removes the basename without its trailing slash.FileListobjects with only one element in them are not parsed as arrays #178: one file in aFileListor array was sent as one plain entry, so the server parsed aFileand not[File]. One file now gets a[]key. A key that already ends with[]keeps its name.Closes #185
Closes #178
Closes #175
Closes #139
Closes #148
Closes #172
Closes #157
Type of change
How Has This Been Tested?
Checklist:
The new options have JSDoc, but the README does not describe them yet. ESLint does not run in this repo (ESLint 9 finds no flat config), so the "no new warnings" box is not ticked.
Testing
Commands run
npx vitest run: 66 passed. The new tests for Fieldmethodin values causes form to fail submission #139, Expose default submit handler #148, Automatically reset form on valid submission / loader revalidation #157, Incorrect serialization of zod objects with complex types (transform, refine,...) #172, Form submission triggers client-side navigation when basename is set #175 and Arrays of files orFileListobjects with only one element in them are not parsed as arrays #178 failed before the change. The Cannot clear custom errors when returned by the server #12 test passed before the change.npx tsc --noEmitandnpx prettier src --check: clean.npm run build: success..d.ts. I builtmainand this branch with react-hook-form 7.75, as CI does. Then I installed 7.89 (--no-save) and type-checked a consumer file. Themainbuild fails withProperty 'getErrors' does not existandmissing ... getErrors, resetDefaultValues. This branch compiles with no errors.npx vitest runwith react-hook-form 7.89 installed: 66 passed.Manual test
<RemixFormProvider {...useRemixForm(...)}>. With 7.2.1 you get TS2739. With this branch it compiles.<input name="method" />to a form that useshandleSubmit. With 7.2.1 the submit throwstoLowerCase is not a function(orreplace is not a functionforaction). With this branch it submits.basename: "/app/"on the router, and submit a form. With 7.2.1 the app navigates on the client. With this branch the action runs.multiplefile input, and callparseFormDatain the action. You now get an array with oneFile.How this PR makes testing easy
Each issue has its own test in
src/hook/index.test.tsxorsrc/utilities/index.test.ts, with the issue number in the test name.Risk / rollback
UseRemixFormReturn["handleSubmit"]now has only the event signature. Before, the type also allowed the react-hook-form signaturehandleSubmit(onValid), which did not work at runtime.files[]and notfiles. If an action readsformData.get("files")directly instead of withparseFormData, it does not find one file. With two or more files, nothing changes.Public API change
Before
After
Note: with
submitRawValues: true,defaultSubmitHandlersendsgetValues()and ignores the data that it gets. So do not combine it with the #148 pattern above.