Skip to content

fix: clear server-side field errors on edit (SDK-923)#2202

Open
jeffredodd wants to merge 2 commits into
mainfrom
fix/SDK-923-clear-server-errors-on-edit
Open

fix: clear server-side field errors on edit (SDK-923)#2202
jeffredodd wants to merge 2 commits into
mainfrom
fix/SDK-923-clear-server-errors-on-edit

Conversation

@jeffredodd

@jeffredodd jeffredodd commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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 server fieldErrors onto RHF via setError(name, { type: 'custom', message }).
  • useField.handleChange never called clearErrors, and forms run mode: 'onSubmit', so RHF didn't reclear on change either. The custom error sat there forever.
  • Fix: in handleChange, when the field already has a type: 'custom' error, call clearErrors(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 — PaySchedule already 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)
  • Verified the new positive tests fail without the fix and pass with it (red → green); the negative test (client-side required error not cleared on edit) passes in both states, confirming the change is surgical.
  • Manual repro in sdk-app: open Pay Schedule, submit a date combination that trips a server validator, confirm the date error appears, edit the date, confirm the error clears, then resubmit successfully.
  • Spot-check a non-date field elsewhere (e.g., Compensation rate) to confirm the same clear-on-edit behavior across field types.

🤖 Generated with Claude Code


const handleChange = (updatedValue: TValue) => {
const value = transform ? transform(updatedValue) : updatedValue
if (fieldState.error?.type === 'custom') {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed errors are coming back as type custom from the server. Seems save if a user is indeed changing the input.

@jeffredodd jeffredodd marked this pull request as ready for review June 18, 2026 15:27
@jeffredodd jeffredodd requested a review from a team as a code owner June 18, 2026 15:27
@jeffredodd jeffredodd marked this pull request as draft June 24, 2026 16:29
@jeffredodd jeffredodd force-pushed the fix/SDK-923-clear-server-errors-on-edit branch 2 times, most recently from 93ed3b5 to a39ef68 Compare June 24, 2026 17:55
@jeffredodd jeffredodd marked this pull request as ready for review June 25, 2026 17:57
@jeffredodd jeffredodd force-pushed the fix/SDK-923-clear-server-errors-on-edit branch from a39ef68 to eee8731 Compare June 25, 2026 17:57
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])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@jeffredodd jeffredodd force-pushed the fix/SDK-923-clear-server-errors-on-edit branch from 1caff44 to e4bc15a Compare July 1, 2026 18:42
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.

2 participants