Repository navigation
feat(react): add useForm onSuccess / onError callbacks - #621
Merged
cpojer merged 2 commits intoOct 28, 2026
Merged
Conversation
Fixes voidzero-dev#524 ## Summary React `form.post` / `put` / `patch` / `delete` are `useActionState` actions, so they cannot be awaited. Apps that need a toast, reset, focus move, or dialog close after submit currently watch `pending` + `wasSuccessful` in an effect. This adds optional `onSuccess` / `onError` on the third `useForm` argument (via shared `ActionFormOptions`), called from the action after success or error state is set. ## Changes - Invoke `onSuccess` after a successful submit (after `resetOnSuccess` / success flags / recently-successful timer); not on abort. - Invoke `onError` with field validation map (422) or `VoidActionError`; not on abort. - Types on `ActionFormBaseOptions` + codegen for `ActionFormOptions`. - React-only (this issue's scope); Vue/Solid/Svelte untouched; voidzero-dev#523 not included. ## Testing - `pnpm exec vp test run packages/react/test/unit/use-form.test.ts` (5 passed) - `pnpm exec vp run --filter ./packages/react typecheck` - `pnpm exec vp test run packages/void/test/unit/route-types.test.ts` (18 passed) ## Choices to check - Added `happy-dom` (catalog + `@void/react` devDependency) so the new hook unit tests can mount with `createRoot`. Alternatives considered: skip unit tests for this path, or cover with Playwright (heavier for a few callback branches). Happy to drop the tests or switch approach if maintainers prefer keeping the React package free of a DOM test runner.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
cpojer
self-requested a review
October 27, 2026 15:06
cpojer
previously approved these changes
Oct 28, 2026
cpojer
left a comment
Member
There was a problem hiding this comment.
Thanks, let me make some changes here – this is not concurrent safe.
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.
Fixes #524
Add React-only
onSuccessandonErroroptions touseForm()for submission feedback and dialog updates while retaining native React form Actions.Each submission uses its Action's callback closure, so suspended renders cannot replace an in-flight callback. Callbacks may return
Promise<void>; the Action awaits them, keepspendingtrue, and sends callback failures to React's error boundary. Validation failures pass the field-error map toonError; other handled action failures passVoidActionError. Aborted submissions invoke neither callback.Callbacks report submission results before the updated UI commits. The forms guide documents using effects or ref callbacks for focusing newly rendered elements. Callback types stay in the React adapter, and
FormOptionspreserves generated action-body and route-parameter checks.Regression coverage exercises the public
useForm()API in Strict Mode, suspended renders, async success and error callbacks, rejection handling, aborts, and repeated submissions. Type-only cases cover React callback inference and reject unsupported callbacks in Vue, Svelte, and Solid. Happy DOM is a development dependency for the React hook tests.Validation:
vp test run: 14,993 passing tests, 31 skipped.vp run build:alland the metaframework artifact check.vp run check: all 33 typecheck tasks passed.vp run build:docs.