Skip to content
Source
Sign inSign up
TanStack/form

fix(react-form): [v2] rerender `ArrayField` when the array's own errors change #2444

Openkkatalz(GitHub profile, opens in a new tab)wants to merge 1 commit intoalpha fromrefs/pull/2444/headopened

Showing 5 changed files with 91 additions and 2 deletions (loading 2).

x
0 of 5 viewed, 5 left
6 additions and 0 deletions.changeset/loud-arrays-report.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/react-form': patch
+'@tanstack/preact-form': patch
+---
+​
+Rerender `ArrayField` when the array's own errors change, so an array-level validator error shows without a change to the array's length.
6 additions and 2 deletionspackages/preact-form/src/PreactForm/fieldSubscriptions.lib.tsModified
View file
@@ -1,4 +1,4 @@
-import { useSelector } from '@tanstack/preact-store'
+import { shallow, useSelector } from '@tanstack/preact-store'
import { useMemo } from 'preact/compat'
import type { AnyInternalFieldApi } from '@tanstack/form-core/internals'
​
@@ -23,10 +23,14 @@
fieldApi.atom,
(state) => state.meta._arrayVersion,
+ const errors = useSelector(fieldApi.atom, (state) => state.meta.errors, {
+ compare: shallow,
+ })
​
return useMemo(() => {
void length
void arrayVersion
+ void errors
return Object.create(fieldApi)
- }, [fieldApi, arrayVersion, length])
+ }, [fieldApi, arrayVersion, length, errors])