Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their 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 (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughForm and field listener contexts now expose optional ChangesPrevious 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: Pass previous form values
_notifyFieldChange->>_notifyEvent: Forward previous form values
_notifyEvent->>runFieldListenerPipeline: Resolve field prevValue
_notifyFieldChange->>runFormListenerPipeline: Provide form prevValue
Suggested reviewers: Merge Risk: ⚪ Minimal · up to Listeners receive the value immediately before a change, including in the array-filter notification path. No material regression is established, so the change is mergeable subject to normal CI. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
…spec The target field does not change, so its listener receives its own previous value, an empty string, on both calls. This was the one watched-field assertion the earlier commits did not update, and it failed pnpm test:lib. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran Now run on this branch: form-core 29 files / 606 tests pass, and |
🎯 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, the value immediately before the change that triggered the listener.prevValueisundefined.