fix(forms): clearing an optional text field on edit now persists - #40
Merged
Conversation
The #37 fix stripped "" to undefined for EVERY optional field so an untouched optional uuid/date default would stop blocking submit. That over-reached: for a plain optional string, "" is a legitimate value (the user clearing the field), and stripping it meant the cleared key reached drizzle .set() as undefined, which is skipped, so the old value silently survived a save the UI reported as successful (CrudPage edit forms: suppliers, policies, kpis, patches, changes, improvements, exercises, audits, reviews, and supplier-portal profile). Now "" is stripped only for fields whose own validator rejects it (uuid/date/number/url/enum), keeping it for plain text so clears persist. The strip set is derived per-field via fieldSchema.safeParse(""), so it stays correct as schemas evolve — no hand-maintained field list. Verified against asset/supplier/risk validators: numeric/boolean/date/FK fields strip (original create-submit bug stays fixed), plain text fields (description, owner, hostname, contactName, ...) keep "" (regression fixed).
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.
The bug (live on prod, regression from #37)
#37 fixed "optional empty fields block create submit" by stripping
"" → undefinedfor every optional field. That over-reached: for a plain optional string,""is a legitimate value — the user clearing the field. Stripping it meant the cleared key reached drizzle.set()asundefined(skipped), so the old value silently survived a save the UI reported as successful.Repro on current prod: edit any record in
/de/risks(or suppliers, policies, kpis, patches…), clear an optional text field like description, save, reload — the old text comes back. Found by 4 independent review finders converging on the same trace:CrudPage onUpdate → *UpdateSchema.partial() → drizzle .set().The fix
Strip
""only for fields whose own validator rejects""(uuid FK, date, number, url, enum) — those need it to submit. Keep""for plain optional text so clears persist. The strip set is derived per field viafieldSchema.safeParse(""), so it self-adjusts as schemas change; no hand-maintained list.Verified
Against
asset/supplier/riskvalidators (script in the commit):quantity,customerCompanyId,lastPatchDate,residualLikelihood, booleans…description,owner,hostname,contactName,category,riskOwner…Typecheck clean. Regression e2e test (edit → clear → reload → assert empty) is added on the e2e branch to guard it going forward.
Not merging without your go.
🤖 Generated with Claude Code
https://claude.ai/code/session_01De1NY1HDUJkkwetVKTbYtH