Skip to content

fix(react-form): re-render mode="array" fields after swapValues/moveValue - #2073

Closed
isaackaara wants to merge 1 commit into
TanStack:mainfrom
isaackaara:fix/array-mode-swap-move-rerender
Closed

isaackaara wants to merge 1 commit into
TanStack:mainfrom
isaackaara:fix/array-mode-swap-move-rerender

Conversation

@isaackaara

Copy link
Copy Markdown
Contributor

Closes #2018

What broke

When using <Field mode="array">, calling swapValues or moveValue updated the internal form state correctly but the component did not re-render. The UI kept showing the old order until something else triggered a re-render.

Root cause: PR #1930 (fixing #1925) changed the useStore selector for mode="array" to only track array length, not full value. That stopped the unwanted re-renders from child property changes — but as a side effect, reordering operations that keep the array length the same (swap, move) also stopped triggering re-renders.

The fix

Added a useReducer version counter (arrayStructuralVersion) that increments every time swapValues or moveValue is called. The counter is included in the useMemo dependency array, so any reorder forces a re-render.

The mode="array" length-only optimization from #1930 is kept intact — child property changes still do not cause unnecessary array field re-renders.

Testing

…alue

The array-length-only selector (introduced in TanStack#1930 to fix TanStack#1925) prevented
re-renders when items were swapped or moved because the array length didn't
change. A small useReducer version counter now bumps on each swapValues/
moveValue call, forcing a re-render so the displayed order stays in sync.

Fixes TanStack#2018
@changeset-bot

changeset-bot Bot commented Mar 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cdf9351

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

This PR includes changesets to release 13 packages
Name Type
@tanstack/react-form Patch
@tanstack/react-form-nextjs Patch
@tanstack/react-form-remix Patch
@tanstack/react-form-start Patch
@tanstack/form-core Patch
@tanstack/angular-form Patch
@tanstack/vue-form Patch
@tanstack/solid-form Patch
@tanstack/svelte-form Patch
@tanstack/form-devtools Patch
@tanstack/lit-form Patch
@tanstack/react-form-devtools Patch
@tanstack/solid-form-devtools Patch

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

@nx-cloud

nx-cloud Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit cdf9351

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 1m 21s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-10 11:19:15 UTC

@pkg-pr-new

pkg-pr-new Bot commented Mar 10, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/form-devtools

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

@tanstack/lit-form

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

@tanstack/react-form

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

@tanstack/react-form-devtools

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

@tanstack/react-form-nextjs

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

@tanstack/react-form-remix

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

@tanstack/react-form-start

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

@tanstack/solid-form

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

@tanstack/solid-form-devtools

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

@tanstack/svelte-form

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

@tanstack/vue-form

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

commit: 7cb07a5

@crutchcorn

Copy link
Copy Markdown
Contributor

We should not overwrite the methods in the specific adapters. Instead, we should either expose some kind of state from core and consume that or find another method to reflect the changes. Closing for now

@crutchcorn crutchcorn closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field with mode="array" does not re-render after swapValues / moveValue since version 1.27.4

2 participants