fix: clear server-side field errors on edit (SDK-923)#2202
Open
jeffredodd wants to merge 2 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
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?)
Server-side validation errors on the two anchor date fields are mirrored onto RHF as `type: 'custom'` errors by SDKFormProvider. Because the form runs in `onSubmit` mode, these errors don't clear when the user edits the field, blocking resubmission until a page refresh. `usePayScheduleForm` now exposes `handleDateFieldsBlur`, a plain focus handler that clears any `type: 'custom'` error on the two anchor date fields and clears `submitError` (so SDKFormProvider's sync effect doesn't re-apply the errors on the next render). `PayScheduleForm.tsx` wires it to `onBlur` on a `display: contents` div wrapping just the two date fields. No `formMethods.subscribe`, no shared-form-layer changes, no new context. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1caff44 to
e4bc15a
Compare
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