fix(react-form): re-render mode="array" fields after swapValues/moveValue#2073
Open
isaackaara wants to merge 1 commit intoTanStack:mainfrom
Open
fix(react-form): re-render mode="array" fields after swapValues/moveValue#2073isaackaara wants to merge 1 commit intoTanStack:mainfrom
isaackaara wants to merge 1 commit intoTanStack:mainfrom
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.