@@ -223,32 +223,37 @@ export function useField<
223223
224224 // For array mode, only track length changes to avoid re-renders when child properties change
225225 // See: https://github.com/TanStack/form/issues/1925
226- // Consolidate all field state subscriptions into a single useStore call
227- // to reduce subscription overhead (1 subscription instead of 7)
228- const isArrayMode = opts . mode === 'array'
229- const reactiveState = useStore (
226+ const reactiveStateValue = useStore (
230227 fieldApi . store ,
231- ( state ) => {
232- return {
233- value : isArrayMode
234- ? Object . keys ( ( state . value as unknown ) ?? [ ] ) . length
235- : state . value ,
236- isTouched : state . meta . isTouched ,
237- isBlurred : state . meta . isBlurred ,
238- isDirty : state . meta . isDirty ,
239- errorMap : state . meta . errorMap ,
240- errorSourceMap : state . meta . errorSourceMap ,
241- isValidating : state . meta . isValidating ,
242- }
243- } ,
244- ( a , b ) =>
245- a . value === b . value &&
246- a . isTouched === b . isTouched &&
247- a . isBlurred === b . isBlurred &&
248- a . isDirty === b . isDirty &&
249- a . errorMap === b . errorMap &&
250- a . errorSourceMap === b . errorSourceMap &&
251- a . isValidating === b . isValidating ,
228+ ( opts . mode === 'array'
229+ ? ( state ) => Object . keys ( ( state . value as unknown ) ?? [ ] ) . length
230+ : ( state ) => state . value ) as (
231+ state : typeof fieldApi . state ,
232+ ) => TData | number ,
233+ )
234+ const reactiveMetaIsTouched = useStore (
235+ fieldApi . store ,
236+ ( state ) => state . meta . isTouched ,
237+ )
238+ const reactiveMetaIsBlurred = useStore (
239+ fieldApi . store ,
240+ ( state ) => state . meta . isBlurred ,
241+ )
242+ const reactiveMetaIsDirty = useStore (
243+ fieldApi . store ,
244+ ( state ) => state . meta . isDirty ,
245+ )
246+ const reactiveMetaErrorMap = useStore (
247+ fieldApi . store ,
248+ ( state ) => state . meta . errorMap ,
249+ )
250+ const reactiveMetaErrorSourceMap = useStore (
251+ fieldApi . store ,
252+ ( state ) => state . meta . errorSourceMap ,
253+ )
254+ const reactiveMetaIsValidating = useStore (
255+ fieldApi . store ,
256+ ( state ) => state . meta . isValidating ,
252257 )
253258
254259 // This makes me sad, but if I understand correctly, this is what we have to do for reactivity to work properly with React compiler.
@@ -257,18 +262,19 @@ export function useField<
257262 ...fieldApi ,
258263 get state ( ) {
259264 return {
260- // For array mode, reactiveState.value is the length (for reactivity tracking),
265+ // For array mode, reactiveStateValue is the length (for reactivity tracking),
261266 // so we need to get the actual value from fieldApi
262- value : isArrayMode ? fieldApi . state . value : reactiveState . value ,
267+ value :
268+ opts . mode === 'array' ? fieldApi . state . value : reactiveStateValue ,
263269 get meta ( ) {
264270 return {
265271 ...fieldApi . state . meta ,
266- isTouched : reactiveState . isTouched ,
267- isBlurred : reactiveState . isBlurred ,
268- isDirty : reactiveState . isDirty ,
269- errorMap : reactiveState . errorMap ,
270- errorSourceMap : reactiveState . errorSourceMap ,
271- isValidating : reactiveState . isValidating ,
272+ isTouched : reactiveMetaIsTouched ,
273+ isBlurred : reactiveMetaIsBlurred ,
274+ isDirty : reactiveMetaIsDirty ,
275+ errorMap : reactiveMetaErrorMap ,
276+ errorSourceMap : reactiveMetaErrorSourceMap ,
277+ isValidating : reactiveMetaIsValidating ,
272278 } satisfies AnyFieldMeta
273279 } ,
274280 } satisfies AnyFieldApi [ 'state' ]
@@ -318,7 +324,17 @@ export function useField<
318324 extendedApi . Field = Field as never
319325
320326 return extendedApi
321- } , [ fieldApi , isArrayMode , reactiveState ] )
327+ } , [
328+ fieldApi ,
329+ opts . mode ,
330+ reactiveStateValue ,
331+ reactiveMetaIsTouched ,
332+ reactiveMetaIsBlurred ,
333+ reactiveMetaIsDirty ,
334+ reactiveMetaErrorMap ,
335+ reactiveMetaErrorSourceMap ,
336+ reactiveMetaIsValidating ,
337+ ] )
322338
323339 useIsomorphicLayoutEffect ( fieldApi . mount , [ fieldApi ] )
324340
0 commit comments