From 2785904e38e92589b0aa410f5b82cb039d963028 Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Sun, 15 Mar 2026 17:03:09 -0700 Subject: [PATCH] Fix react-hook-form task 153: handleSubmit 3rd arg type mismatch The combined.patch uses handleSubmit(onValid, onInvalid, options) where options is an object, but the test patch passes onFinally as a bare function in the 3rd positional argument. Since the implementation checks options?.onFinally and options is a function (not an object), onFinally is never invoked and all 3 onFinally tests fail. Add runtime type detection to accept both call styles: handleSubmit(valid, invalid, onFinallyFn) -- bare function handleSubmit(valid, invalid, { onFinally: fn }) -- options object --- dataset/react_hook_form_task/task153/combined.patch | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dataset/react_hook_form_task/task153/combined.patch b/dataset/react_hook_form_task/task153/combined.patch index c027645..c541980 100644 --- a/dataset/react_hook_form_task/task153/combined.patch +++ b/dataset/react_hook_form_task/task153/combined.patch @@ -2,17 +2,22 @@ diff --git a/src/logic/createFormControl.ts b/src/logic/createFormControl.ts index f7079332..4fa17575 100644 --- a/src/logic/createFormControl.ts +++ b/src/logic/createFormControl.ts -@@ -1097,7 +1097,8 @@ export function createFormControl< +@@ -1097,7 +1097,13 @@ export function createFormControl< }; const handleSubmit: UseFormHandleSubmit = - (onValid, onInvalid) => async (e) => { -+ (onValid, onInvalid, options) => async (e?, context?) => { ++ (onValid, onInvalid, optionsOrOnFinally) => async (e?, context?) => { ++ // Accept onFinally as a bare function (3rd positional arg) or as ++ // options.onFinally for backward compatibility with both call styles. ++ const options = typeof optionsOrOnFinally === 'function' ++ ? { onFinally: optionsOrOnFinally } ++ : optionsOrOnFinally; + let onValidError: Error | undefined = undefined; if (e) { e.preventDefault && e.preventDefault(); e.persist && e.persist(); -@@ -1108,36 +1109,107 @@ export function createFormControl< +@@ -1108,36 +1114,107 @@ export function createFormControl< isSubmitting: true, }); @@ -182,7 +187,7 @@ index 2f20133e..c07f7e4a 100644 - onInvalid?: SubmitErrorHandler, -) => (e?: React.BaseSyntheticEvent) => Promise; + onInvalid?: SubmitErrorHandler, -+ options?: { ++ optionsOrOnFinally?: ((formState: FormState) => void | Promise) | { + onBeforeValidate?: (data: TFieldValues) => Promise | void; + onAfterValidate?: (errors: FieldErrors, data: TFieldValues) => Promise | void; + preventFocusOnError?: boolean;