Skip to content

fix(react): derive form state from submission outcomes and guard concurrent submits - #738

Open
kotarotaniguchi0523 wants to merge 1 commit into
voidzero-dev:mainfrom
kotarotaniguchi0523:refactor/react-form-state
Open

kotarotaniguchi0523 wants to merge 1 commit into
voidzero-dev:mainfrom
kotarotaniguchi0523:refactor/react-form-state

Conversation

@kotarotaniguchi0523

Copy link
Copy Markdown

Summary

  • Derive useForm() status (errors, error, hasChanges, wasSuccessful, recentlySuccessful) from the useActionState outcome instead of syncing separate states and refs across await.
  • Snapshot form data at dispatch time so queued React actions and in-flight edits (including with resetOnSuccess: true) keep their submitted payload and baseline.
  • Clear previous errors and success state when a submission starts, without reviving them if the submission aborts.
  • Ensure reset(), setError(), clearErrors(), and clearError() inside onSuccess / onError apply to the new outcome without exposing uncommitted defaults during await.
  • Guard useIslandForm() with a request ID so the latest submission owns pending and UI state across out-of-order completions.
  • Check 429 retryAt deadlines directly in <Form> onSubmit instead of mounting a timer effect.

Test plan

  • vp fmt --check & vp lint
  • vp run build & vp run check:sdk
  • vp test run packages/react/test/unit

…urrent submits

- Represent useForm submission results with a discriminated union (SubmissionOutcome) owned by useActionState, deriving errors, error, hasChanges, wasSuccessful, and recentlySuccessful without redundant state or refs.
- Snapshot form data and dispatchData at dispatch time so synchronous setData() calls, in-flight edits (including under resetOnSuccess), and queued React actions preserve their submitted payload and post-success baseline.
- Scope callbackOutcomeRef across async onError and synchronous onSuccess so reset(), setError(), clearErrors(), and clearError() inside callbacks operate on the incoming outcome without leaking uncommitted defaults to external UI interactions during await.
- Return a fresh idle outcome when a submission aborts so previous validation errors or success states do not revive.
- Represent useIslandForm state with a single IslandOutcome union and requestId so the latest started submission owns pending and UI state across completion orders.
- Check 429 retryAt deadlines directly in <Form> onSubmit instead of mounting timer state and effects.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant