Repository navigation
fix(react-form): re-render mode="array" fields after swapValues/moveValue - #2073
isaackaara wants to merge 1 commit into
Conversation
…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 detectedLatest commit: cdf9351 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
|
| 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
|
We should not overwrite the methods in the specific adapters. Instead, we should either expose some kind of state from |

Closes #2018
What broke
When using
<Field mode="array">, callingswapValuesormoveValueupdated 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
useStoreselector formode="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
useReducerversion counter (arrayStructuralVersion) that increments every timeswapValuesormoveValueis called. The counter is included in theuseMemodependency 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
swapValuesandmoveValueon amode="array"field and verifies the component re-renders and displays the updated order.arrayField rerenders when a property on any array element is mutated (regression in 1.27.0) #1925 (should not rerender array field when child field value changes) still passes.