Fix ValidationGroup visited flag not propagating to fields#1294
Merged
Conversation
Field.disableOrValidate coalesced the resolved `visited` value back into `data.visited`. When prepareData was skipped (the field's own bound data unchanged), a stale resolved value shadowed an updated `parentVisited`. This surfaced when a ValidationGroup's `visited` binding was initialized to `false` and later set to `true`. Add a `data._visited` backing field, mirroring `_disabled`, `_readOnly`, `_viewMode` and `_tabOnEnterKey`, so the field's own `visited` prop is preserved across renders. Fixes #1276
✅ Deploy Preview for cxjs-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Issue
Fixes #1276.
When a
ValidationGroup'svisitedbinding is initialized tofalseand later set totrue, the change is not propagated to child fields. If the binding is left uninitialized, it works.Root cause
Field.disableOrValidateresolved thevisitedflag by coalescingdata.visitedinto itself:The four sibling flags (
disabled,readOnly,viewMode,tabOnEnterKey) each read a separate backing field (data._disabled, …) populated inprepareData;visitedhad none.When a field's own bound data is unchanged,
prepareDatais skipped (the memoized selector returns a reference-equalrawData), soinstance.datais the stale object from the previous render.disableOrValidate, re-invoked fromexploreon aparentVisitedchange, then reads the already-coalesced staledata.visited. Sincecoalescetreatsfalseas a defined value, a stalefalseshadows the newparentVisitedoftrue. With no initialization the stale value isundefined, whichcoalesceskips — hence "works without init".Fix
Add a
data._visitedbacking field inprepareData(mirroring_disabled,_readOnly,_viewMode,_tabOnEnterKey) and read it indisableOrValidate, so the field's ownvisitedprop is preserved across renders.Test
Added a regression test to
ValidationGroup.spec.tsx. Verified it fails before the fix (AssertionError: false == true) and passes after. Full suite (508 tests) passes.