You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@for does not properly track an array of signal form fields #63882
Which @angular/* package(s) are the source of the bug?
forms
Is this a regression?
No
Description
When using @for to render an array of fields from a signal form instance, @for does not properly track changes to the order of array values.
The reproduction demonstrates the behavior of @for when used to render an array whose values are rearranged. After the initial render the first DOM element rendered for each array item is colored red with a dashed border.
When the array elements are reordered, we'd expect their corresponding rendered <input> elements to be reordered in the DOM.
This works as expected for an array. No bindings are updated, and the DOM elements are reordered.
This does not work as expected for an array of fields. Bindings are updated, and the DOM elements are left untouched. Superficially, this appears to work, as the value in the inputs is swapped. However, as demonstrated by the red dashed border, one can observe that the input itself is not swapped as expected.
Please provide a link to a minimal reproduction of the bug
For some additional context, the only reason I encountered this case was that I was trying to devise a test case to test reactivity in the name property of form fields. It appears that the only reason this value is reactive is to account for an array of form fields. If the index of the field changes in the form, in theory its name is updated to reflect that change.
However, as demonstrated here, I'm unable to actually produce an example that exercises that behavior.
I think this is actually the intended behavior for an array of primitive values in signal forms. For primitive values, if we see the model change from ['a', 'b'] to ['b', 'a'] we don't really know if the user intended to swap the actual ui controls, or swap their values. So for arrays of primitive values we track them by index.
Activity
leonsenft commentedon Sep 17, 2025
For some additional context, the only reason I encountered this case was that I was trying to devise a test case to test reactivity in the
nameproperty of form fields. It appears that the only reason this value is reactive is to account for an array of form fields. If the index of the field changes in the form, in theory its name is updated to reflect that change.However, as demonstrated here, I'm unable to actually produce an example that exercises that behavior.
fix(forms): test that common field states are propagated to controls
JeanMeche commentedon Sep 17, 2025
The issue here is that
Fieldis not an array but an iterable and the reconcilation algorithm treats them differently.cc @pkozlowski-opensource
leonsenft commentedon Sep 17, 2025
I think this is one half of the issue. The other half has to do with how the
form()internally createsFieldinstances for individual array elements.fix(forms): test that common field states are propagated to controls
fix(forms): test that common field states are propagated to controls
fix(forms): test that common field states are propagated to controls
fix(forms): test that common field states are propagated to controls
fix(forms): test that common field states are propagated to controls (#…
mmalerba commentedon Nov 13, 2025
I think this is actually the intended behavior for an array of primitive values in signal forms. For primitive values, if we see the model change from
['a', 'b']to['b', 'a']we don't really know if the user intended to swap the actual ui controls, or swap their values. So for arrays of primitive values we track them by index.For objects however, we can use the object identity as a tracking key. So if you want that style of tracking in your form, you can use wrapper objects to achieve it: https://stackblitz.com/edit/for-signal-forms-aqntmqf7?file=src%2Fmain.ts
angular-automatic-lock-bot commentedon Dec 14, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.