Skip to content
Source
Sign inSign up
TanStack/form

fix(react-form): prevent array field re-render when child property changes #1930

Mergedtt-a1i(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/1930/headmerged by crutchcorn(GitHub profile, opens in a new tab)

Summary

  • Fix array fields with mode="array" incorrectly re-rendering when a property on any array element is mutated
  • This was a regression introduced in v1.27.0 by the React Compiler compatibility changes (#1893)

Problem

As reported in #1925, starting from v1.27.0, when working with a form.Field that uses mode="array", when any child Field under the array Field is changed, the entire array Field re-renders.

Root Cause

In the React Compiler fix (#1893), a new reactiveStateValue subscription was added:

const reactiveStateValue = useStore(fieldApi.store, (state) => state.value)

This subscribes to the entire state.value. For array fields, when any child property changes, the array reference changes, causing reactiveStateValue to change, which triggers extendedFieldApi recreation and component re-render.

Solution

Make the reactiveStateValue subscription aware of mode:

const reactiveStateValue = useStore(
  fieldApi.store,
  (opts.mode === 'array'
    ? (state) => Object.keys((state.value as unknown) ?? []).length
    : (state) => state.value) as (state: typeof fieldApi.state) => TData | number,
)

For mode="array":

  • reactiveStateValue now tracks only the array length
  • The state.value getter returns the actual value from fieldApi.state.value
  • This ensures re-renders only occur when items are added/removed, not when properties change

Test Plan

  • Added test case: should not rerender array field when child field value changes
  • All existing tests pass (79 tests in react-form, 403 tests in form-core)

Fixes #1925

    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 63f5615bb59081b4d3ed7d43a3a3ff3af18d2cad

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 13 packages
      NameType
      @tanstack/react-formPatch
      @tanstack/react-form-nextjsPatch
      @tanstack/react-form-remixPatch
      @tanstack/react-form-startPatch
      @tanstack/form-corePatch
      @tanstack/angular-formPatch
      @tanstack/vue-formPatch
      @tanstack/solid-formPatch
      @tanstack/svelte-formPatch
      @tanstack/form-devtoolsPatch
      @tanstack/lit-formPatch
      @tanstack/react-form-devtoolsPatch
      @tanstack/solid-form-devtoolsPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. crutchcorn(GitHub profile, opens in a new tab) approved these changes

      Makes perfect sense to me! Thank you for this!

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 63f5615bb59081b4d3ed7d43a3a3ff3af18d2cad

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded1m 16sView ↗
      nx run-many --target=build --exclude=examples/**✅ Succeeded13sView ↗

      ☁️ Nx Cloud last updated this comment at 2025-12-15 11:47:06 UTC

    4. More templates

      @tanstack/angular-form

      npm i https://pkg.pr.new/@tanstack/angular-form@1930

      @tanstack/form-core

      npm i https://pkg.pr.new/@tanstack/form-core@1930

      @tanstack/form-devtools

      npm i https://pkg.pr.new/@tanstack/form-devtools@1930

      @tanstack/lit-form

      npm i https://pkg.pr.new/@tanstack/lit-form@1930

      @tanstack/react-form

      npm i https://pkg.pr.new/@tanstack/react-form@1930

      @tanstack/react-form-devtools

      npm i https://pkg.pr.new/@tanstack/react-form-devtools@1930

      @tanstack/react-form-nextjs

      npm i https://pkg.pr.new/@tanstack/react-form-nextjs@1930

      @tanstack/react-form-remix

      npm i https://pkg.pr.new/@tanstack/react-form-remix@1930

      @tanstack/react-form-start

      npm i https://pkg.pr.new/@tanstack/react-form-start@1930

      @tanstack/solid-form

      npm i https://pkg.pr.new/@tanstack/solid-form@1930

      @tanstack/solid-form-devtools

      npm i https://pkg.pr.new/@tanstack/solid-form-devtools@1930

      @tanstack/svelte-form

      npm i https://pkg.pr.new/@tanstack/svelte-form@1930

      @tanstack/vue-form

      npm i https://pkg.pr.new/@tanstack/vue-form@1930

      commit: 63f5615

    5. codecov[bot](GitHub profile, opens in a new tab)commented

      Codecov Report

      :white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 54.11%. Comparing base (6892ed0) to head (63f5615). :warning: Report is 98 commits behind head on main.

      Additional details and impacted files
      @@             Coverage Diff             @@
      ##             main    #1930       +/-   ##
      ===========================================
      - Coverage   90.35%   54.11%   -36.25%     
      ===========================================
        Files          38       18       -20     
        Lines        1752      231     -1521     
        Branches      444       34      -410     
      ===========================================
      - Hits         1583      125     -1458     
      + Misses        149       94       -55     
      + Partials       20       12        -8     

      :umbrella: View full report in Codecov by Sentry. :loudspeaker: Have feedback on the report? Share it here.

      :rocket: New features to boost your workflow:

      • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
      • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
  • heavely depended on this behaviour, any way to bypass?

  • Sign in to join this conversation.