feat(hooks): reactive values + keepDirtyValues for useForm - #80
Merged
Conversation
Forms backed by props/server data can now pass a reactive `values` option:
when its content changes (deep-compared, so a new-object/same-content render
is a no-op), the form re-syncs; it also seeds the initial state (precedence
over defaultValues). `keepDirtyValues: true` preserves the user's in-progress
edits while untouched fields sync (RHF `values`+`resetOptions:{keepDirtyValues}`
/ Formik `enableReinitialize`).
Dirty tracking is a mutation-driven set, so writing values via setFormState
doesn't disturb it — keepDirty is a per-path "which value wins" merge
(setNestedValue, nested-path aware). 7 runtime tests. Minor, additive.
Notes: `values` replaces the whole value object; isDirty is vs the original
defaultValues (not synced values); File/Blob in reactive values won't re-sync
(deep-compare can't distinguish files).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
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.
Roadmap item B / P1 — reactive external
values, the one real parity gap the audit + feature-inventory research both flagged (RHFvaluesprop +resetOptions; FormikenableReinitialize).What
A reactive
valuesoption onuseFormfor forms backed by props/server data:values's content changes (deep-compared, so a new-object/same-content render is a no-op), the form re-syncs. It also seeds the initial state (precedence overdefaultValues).keepDirtyValues: truepreserves fields the user is mid-editing while untouched fields sync.Why it's clean
el-form tracks dirty via a mutation-driven set, so writing values through
setFormStatedoesn't disturb dirty tracking —keepDirtyValuesis a per-path "which value wins" merge (setNestedValue, nested-path aware). No dirty-baseline reconciliation needed.Caveats (documented in the changeset + migration guide)
valuesreplaces the whole value object (provide the full shape; omitted keys drop) — matches RHF.isDirtyis measured against the originaldefaultValues, not the latest syncedvalues(consistent with el-form's existingreset({values})).File/Blobin reactivevalues— the deep-compare can't distinguish files, so a swap won't re-sync (a pre-existingdeepEquallimitation; flagged for a future fix).Verification
keepDirtyValuesbranches,undefined→defined, and nested dirty-field preservation.deepEqual) is pre-existing and documented.Design:
docs/superpowers/specs/2026-06-09-reactive-values-design.md. Minor changeset (additive). Deferred: fullresetOptionssurface (keepErrors/keepTouched/…) — YAGNI for v1.🤖 Generated with Claude Code