Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: TanStack/form/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesPrevious listener values
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant setFieldValue
participant _notifyFieldChange
participant _notifyEvent
participant runFieldListenerPipeline
participant runFormListenerPipeline
setFieldValue->>_notifyFieldChange: Capture and pass previous form values
_notifyFieldChange->>_notifyEvent: Forward previous form values
_notifyEvent->>runFieldListenerPipeline: Resolve field prevValue
_notifyFieldChange->>runFormListenerPipeline: Provide form prevValue
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎯 Changes
Closes #2301.
FormListenerContextandFieldListenerContextnow carry an optionalprevValueholding the value from immediately before the change that invoked the listener, so a change listener can diff against the value it replaced without keeping its own copy.prevValueis only set for'change'events; it isundefinedfor'blur','submit','mount','reset'and'unmount'.setFieldValuesnapshots_atoms.valuesbefore writing and threads that snapshot through_notifyFieldChange→_notifyFormListener/_notifyEvent→_notifyListener.Each field scope derives its own previous value with
getBy(prevFormValues, field.name)rather than receiving the changed field's value. That is what makes the value correct for ancestors and forwatchFieldslisteners: they see what their scope looked like before the change, not the value of the field that triggered it. It also keeps this to one snapshot per mutation, read from an already immutable atom.Debounced listeners behave the way the issue describes: the pipeline builds a context per change and
LiteDebouncerexecutes the last one, so a listener that fires after five rapid changes sees the fourth value asprevValueand the fifth asvalue.filterFieldValueshas a branch that notifies a change even when the filtered array is identical; it now passes the current values soprevValuestays defined for every'change'event.✅ Checklist
pnpm test:pr.🚀 Release Impact
Tests
Added to
packages/form-core/tests/FormApi/listeners.spec.tsandpackages/form-core/tests/FieldApi/listeners.spec.ts:prevValueisundefinedon a non-change triggerExisting change-listener assertions were updated with the new property; the watched-field cases now assert the listening field's own previous value.
Compatibility
prevValueis a new optional property on the listener context, so existing listeners and their destructuring are unaffected. No other behaviour changes.Summary by CodeRabbit
prevValue, showing the value immediately before the change that triggered the listener.prevValueis omitted for non-change events.