Entire `array` Field rerenders when a property on any array element is mutated (regression in 1.27.0)
Describe the bug
Starting from tag 1.27.0, when working with a form.Field that uses mode=array, when any child Field under the array Field is changed (resulting in a modification to a property on one of the array's elements, not to the ordering/size of the array), the entire array Field rerenders.
This is not what happened prior to 1.27.0; in older releases, only the child Field that was touched would re-render (along with anything subscribing to that Field's backing data), as one would expect.
I noticed this in my own application but it even happens in the simple demo on the docs site: https://tanstack.com/form/latest/docs/framework/react/examples/array?panel=sandbox
The result is that in large complex forms that utilize array fields to show many editable/reorderable field groups, performance is quite poor when users type into any field.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/github/tanstack/form/tree/main/examples/react/array?embed=1&theme=dark
Steps to reproduce
- Open devtools and enable rerender highlighting
- Click "Add Person" three times
- Focus Name field for middle person
- Enter a few characters
- Observe the entire array field rerenders, not just the single name field being modified
- The profiler will report "Hook 5 changed" which appears to be the useSyncExternalStore containing the entire array. Array identity is changing?
Expected behavior
When modifying a child form.Field mounted under a form.Field of mode="array", only the child field should re-render when it changes. The entire array form.Field container should not re-render.
How often does this bug happen?
Every time
Screenshots or Videos
Platform
- OS: Linux
- Browser: Firefox 145.0.1
- React: 19.2.0, 19.2.1
TanStack Form adapter
react-form
TanStack Form version
Observed in 1.27.0 / 1.27.2
Does not occur in 1.26.0
TypeScript version
No response
Additional context
- Does not seem to depend on...
- whether the form uses a zod/standard schema validator
- whether
onBlurvsonChangevalidators are used - whether the array Field is using
withFieldGrouporwithFormcomposition - whether React Compiler is being used
I am using React Compiler in my application. However the demo application on the Tanstack Form docs site does not seem to be using Compiler and exhibits the same behavior.
Presumed culprit is one of:
- fix: react compiler should now work in all edgecases (https://github.com/TanStack/form/commit/8afbfc39d7373ec2b516f7c8ff5585ca44098cc1)
- fix: improve perf and fix Start usage (https://github.com/TanStack/form/commit/03c2beed867f097ac61fb6411ce9cd5a9f3b4c58)
Hard for me to tell. Could also be something internal that changed in Tanstack Store, which was updated in 03c2beed867f097ac61fb6411ce9cd5a9f3b4c58? Not familiar with that library.