fix: failed onSubmit is recorded as a successful submit - #103
Merged
Conversation
lastSubmittedValues was written before onSubmit ran, so a failing submit effect (e.g. a rejected network save) still recorded its values as the last-submitted snapshot: hasChangedSinceSubmit turned false (the user believes the failed data was saved), revertToLastSubmit reverted to values whose submission failed, and onBlur auto-submit skipped retrying because values matched the snapshot. Defer the lastSubmittedValues write until onSubmit succeeds; submitCount and touched still update on the attempt so validation errors surface.
Merged
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
High-severity data-integrity bug found in a deep review with executed Red→Green validation:
submitAtomwrotelastSubmittedValuesbefore invokingonSubmit. When the submit effect fails (e.g. the network save rejects), the form still records those values as the last-submitted snapshot, corrupting the change-tracking contract:hasChangedSinceSubmitturns false — the UI tells the user their failed data was saved (silent data loss from the user's perspective)revertToLastSubmitreverts to values whose submission failed, treating them as a good baselineThis matches the README state-lifecycle table's intent ("Submit → lastSubmittedValues = Some(B)" paired with the unsaved-changes use case): last submitted means last saved, not last attempted.
Fix
Run
onSubmitfirst; only commitlastSubmittedValuesafter it succeeds (rebased onto the then-current state).submitCountand touched still update beforeonSubmitso the attempt is counted and validation errors surface on failure.Design note: if "last attempted" semantics were ever intended instead, this should be closed and the README updated to say so — but every consumer surface (
hasChangedSinceSubmit,revertToLastSubmit, onBlur resubmit) behaves correctly only with "last saved".Tests
New regression test: valid values +
onSubmit = Effect.fail("network error")→ assertslastSubmittedValuesstaysNone. Red on unmodified code, Green after. Full suite 302 passed, types + lint clean. Independently re-validated (Red re-confirmed on clean main before applying the fix).Note: a follow-up PR fixing a second, distinct defect in the same lines (stale-snapshot writeback clobbering concurrent edits) is stacked on this branch — merge this one first.