-
-
Notifications
You must be signed in to change notification settings - Fork 526
Description
Describe the bug
This bug was extremely confusing but I finally managed to reproduce it minimally.
When rendering a TransitionGroup
inside of the children
callback of an array form.Field
, and rendering sub-fields inside of that TransitionGroup
, removing any of the items re-creates the last item of the array until the array is back to the size it had in defaultValues
.
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-c9w5c8ae?file=src%2Findex.tsx&preset=node
Steps to reproduce
- Go to the provided link
- Click on
delete
next to any of the inputs - See that the last input is re-added with the value "c"
Expected behavior
I expected the last field to be properly removed from the rendered list
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Browser version: Version 138.0.7204.169 (Official Build) (arm64)
TanStack Form adapter
react-form
TanStack Form version
v1.15.0
TypeScript version
No response
Additional context
react-form
's useField
hook calls field.update
inside of useIsomorphicLayoutEffect
. Usually this isn't an issue, but when using the field inside of a TransitionGroup
from react-transition-group
, the effect fires when the field's state has been removed, before the element itself is properly unmounted, which causes the removed item to be re-added to the state.
This bug goes away if I don't use a nested form.Field
- and manually do the logic for the nested handleChange
. Is there any way to get the benefit of nested form.Field
s without this issue...?
(BTW, don't know if this should be a separate issue, but the link for the "official CodeSandbox examples" in the issue template is wrong...)