fix: treat NaN as empty in form schema so required validation fires for cleared number inputs#1681
Merged
serikjensen merged 2 commits intomainfrom May 6, 2026
Merged
Conversation
…or cleared number inputs react-aria's NumberField emits NaN when its input is cleared. The buildFormSchema makeOptional preprocess only normalized '' and null to undefined, so NaN slipped through to inner field preprocessors like coerceNaN(0) and was silently coerced to 0 — bypassing the superRefine required check (isEmpty(0) is false). Result: required currency fields appeared visually required but never blocked submission when emptied. This affected useFederalTaxesForm (no domain workaround was possible because 0 is a valid W-4 amount) and matched the behavior the payScheduleSchema worked around with a 1–31 range check. Now isEmpty also recognizes NaN and makeOptional reuses it, so cleared numeric inputs normalize to undefined and the required check fires correctly. Adds framework-level coverage in buildFormSchema.test.ts and domain coverage in federalTaxesSchema.test.ts. The compensation test that previously asserted RATE_MINIMUM for NaN rate is updated to assert REQUIRED, which matches the user-facing expectation when an input is empty. Co-authored-by: Cursor <cursoragent@cursor.com>
jeffredodd
approved these changes
May 5, 2026
dmortal
approved these changes
May 5, 2026
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
react-aria's
NumberFieldemitsNaNwhen its input is cleared. InbuildFormSchema, themakeOptionalpreprocess only normalized''andnulltoundefined, soNaNslipped through to inner field preprocessors likecoerceNaN(0)and was silently coerced to0— bypassing thesuperRefinerequired check (isEmpty(0)isfalse). Result: required currency fields looked required (no(optional)label) but the form happily submitted with no value.This was most visible in
useFederalTaxesForm, where every non-filingStatusfield is a number with0as a legitimate value, so the domain-level workaroundpayScheduleSchemauses (a 1–31 range check) wasn't applicable.useCompensationFormwas also affected — clearing the rate field reportedRATE_MINIMUMinstead ofREQUIRED.Changes
src/partner-hook-utils/form/buildFormSchema.ts:isEmptynow also recognizesNaN, andmakeOptionalreusesisEmptyso cleared numeric inputs normalize toundefinedbefore any inner preprocessor runs. The required check then fires correctly.src/partner-hook-utils/form/buildFormSchema.test.ts: framework-level regression coverage for the NaN-required and NaN-optional cases.src/components/Employee/FederalTaxes/shared/useFederalTaxesForm/federalTaxesSchema.test.ts(new): domain coverage matching the original repro —extraWithholding: NaNwithoptionalFieldsToRequire.updateset must produceREQUIRED, while0remains a valid value.src/components/Employee/Compensation/shared/useCompensationForm/useCompensationForm.test.tsx: the test that previously assertedRATE_MINIMUMforNaN ratenow assertsREQUIRED, matching the user-facing expectation when an input is empty.Test plan
npm run test -- --run src/partner-hook-utils src/components/Company/PaySchedule src/components/Employee/FederalTaxes src/components/Employee/Compensation— 268 passingnpm run test -- --run(full suite) — 2470 passingStep 4c: Extra withholdingon the Federal Taxes page and submit — should now block submission with the configuredREQUIREDvalidation message instead of silently coercing to 0Made with Cursor