You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: clean up preserve=false nested list field after index change - #816
When a Field inside Form.List registers, the unregister callback captures the full namePath at registration time. List operations (move / remove) can change a surviving entity's current path while keeping its React identity. On unmount with preserve={false}, cleanup targets the stale path, so the raw store keeps the value at the new path and it reappears when the field remounts. (see #814)
Change
useForm.registerField: resolve the entity's current getNamePath() inside the unregister callback, and use it for store cleanup, observer notification and watcher notification instead of the captured registration path.
Test
Added two regression cases in tests/preserve.test.tsx:
remove the first row, then unmount preserve={false} memo fields → raw store contains no stale memo
move rows, then unmount → raw store contains no stale memo
Both failed before the fix (stale value retained) and pass after. Full suite: 207 passed / 1 skipped; tsc and lint pass.
The fix keeps stale values out of the form store when a nested list field with preserve=false changes index before unmounting. The change is small and covered by new regression tests, so merge risk is minimal.
Pre-merge checks: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Linked Issues check
直接关联 issue #814 的编码要求:当 List 中的 preserve={false} 嵌套 Field 因 move/remove 改变索引后卸载时,store 中不得保留旧值。PR 描述和 AI 摘要称,注销回调改为在注销时读取 entity.getNamePath(),并用该路径执行清理、观察者通知和 watcher 通知。摘要还说明新增两个回归测试(移除首行后卸载;移动行后卸载)…
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a1ae40e3-a91c-4e15-917f-518f2eda9916
Commits
Reviewing files that changed from the base of the PR and between be0cc09 and c6106e4.
Files selected for processing: 2
src/hooks/useForm.ts
tests/preserve.test.tsx
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
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
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.
Problem
When a
FieldinsideForm.Listregisters, the unregister callback captures the fullnamePathat registration time.Listoperations (move/remove) can change a surviving entity's current path while keeping its React identity. On unmount withpreserve={false}, cleanup targets the stale path, so the raw store keeps the value at the new path and it reappears when the field remounts. (see #814)Change
useForm.registerField: resolve the entity's currentgetNamePath()inside the unregister callback, and use it for store cleanup, observer notification and watcher notification instead of the captured registration path.Test
Added two regression cases in
tests/preserve.test.tsx:preserve={false}memo fields → raw store contains no stalememomemoBoth failed before the fix (stale value retained) and pass after. Full suite: 207 passed / 1 skipped;
tscandlintpass.Fixes #814
Summary by CodeRabbit