fix: clear server-side field errors on edit (SDK-923)#2202
Open
jeffredodd wants to merge 4 commits into
Open
Conversation
jeffredodd
commented
Jun 18, 2026
|
|
||
| const handleChange = (updatedValue: TValue) => { | ||
| const value = transform ? transform(updatedValue) : updatedValue | ||
| if (fieldState.error?.type === 'custom') { |
Contributor
Author
There was a problem hiding this comment.
Confirmed errors are coming back as type custom from the server. Seems save if a user is indeed changing the input.
93ed3b5 to
a39ef68
Compare
`SDKFormProvider` mirrors server `fieldErrors` onto the form via
`setError(name, { type: 'custom', ... })`. Without a clear-on-edit
behavior in this form, that error stays set until a full refresh,
blocking resubmission after the user corrects a date — the original
SDK-923 repro.
Subscribe to `formMethods.watch` inside `usePayScheduleForm` and clear
any `type: 'custom'` error on a field as soon as the user edits it.
RHF's values subject only fires for actual value changes (not blur),
so the subscription is narrow.
Client-side validation errors (`required`, `min`, zod-driven, etc.)
are untouched — the type filter only matches the server-error path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a39ef68 to
eee8731
Compare
serikjensen
reviewed
Jun 25, 2026
Comment on lines
+312
to
+327
| // Server-side validation errors (mirrored via SDKFormProvider as | ||
| // `type: 'custom'`) need to clear the moment the user edits a field; | ||
| // otherwise the stale error blocks resubmission until a refresh (SDK-923). | ||
| useEffect(() => { | ||
| const subscription = formMethods.watch((_, info) => { | ||
| const { name } = info | ||
| if (!name) return | ||
| if (formMethods.getFieldState(name).error?.type === 'custom') { | ||
| formMethods.clearErrors(name) | ||
| } | ||
| }) | ||
| return () => { | ||
| subscription.unsubscribe() | ||
| } | ||
| }, [formMethods]) | ||
|
|
Member
There was a problem hiding this comment.
i'm a little worried about doing this subscription based. is this watching each field on the form?
I'm wondering if we could do an event based fix here instead where we could detect changes to the problem fields and clear them if an error is present?
if we keep this approach i think we need to include each formMethod function as an entry in the dep array individually. formMethods in the dep array used to cause infinite renders (maybe they fixed it?)
…vider Address Steve's review: replace the per-render `formMethods.watch` subscription in `usePayScheduleForm` with an event-based clear inside `useField.handleChange`, so the fix lives in the shared form layer and only fires for the field actually being edited. Pair it with an `appliedRef` in `useSyncFieldErrors` so the effect no longer re-applies server errors on every render (which was overwriting the clear and trapping users in a stale error until refresh). Relocate the SDK-923 unit tests onto `useField` and add an 8-case permutation suite for `SDKFormProvider` error clearing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…vider useField is the generic SDK input hook and shouldn't carry form-error policy. Move the type:'custom' clear into useSyncFieldErrors using RHF's per-field `subscribe` API (RHF 7.55+), so we listen only to the fields that actually carry a server error rather than watching the whole form. Switch applied-tracking from a content-string Set to a WeakSet keyed by SDKFieldError identity so an identical-message re-submission still re-applies the error (new SDKError from composeSubmitHandler → new field-error refs). Drop the matching useField unit tests; the SDKFormProvider permutation suite covers it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Revert the SDKFormProvider changes and the generic useField changes — the fix belongs in the PaySchedule form, not in shared infrastructure. Use RHF's per-field `subscribe` (RHF 7.55+) inside `usePayScheduleForm` against ONLY `anchorPayDate` and `anchorEndOfPayPeriod` so we listen exclusively to the fields that can carry a server validation error. On edit of one of those fields with a `type: 'custom'` error: clear the field error AND call `setSubmitError(null)` to drop the upstream source, which prevents `SDKFormProvider`'s sync effect from re-applying the error on the next render. Restore the PaySchedule-local SDK-923 tests (plus negative cases: client-side errors and non-date fields are unaffected). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes SDK-923 — server-side validation errors on form fields blocked resubmission until a page refresh (reported on Pay Schedule date fields, but the bug is SDK-wide).
useSyncFieldErrors(SDKFormProvider) maps serverfieldErrorsonto RHF viasetError(name, { type: 'custom', message }).useField.handleChangenever calledclearErrors, and forms runmode: 'onSubmit', so RHF didn't reclear on change either. The custom error sat there forever.handleChange, when the field already has atype: 'custom'error, callclearErrors(name)before forwarding the new value. Client-side validation errors (required,min, zod-driven, etc.) are untouched — RHF's normal validation loop is unaffected.Despite the ticket framing, this was not a state-machine problem —
PaySchedulealready uses a robot3 machine. The bug was in the shared form layer, so the fix lives there and benefits every form, not just Pay Schedule.Test plan
npm run test -- --run src/components/Common/Fields/hooks/useField.test.tsx(22 pass; 3 new)npm run test -- --run src/partner-hook-utils/form/ src/components/Company/PaySchedule/(152 pass)npm run test -- --run src/components/Common/Fields/(51 pass)requirederror not cleared on edit) passes in both states, confirming the change is surgical.🤖 Generated with Claude Code