Skip to content

@for does not properly track an array of signal form fields #63882

Closed

Description

@leonsenft

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

https://stackblitz.com/edit/for-signal-forms

Activity

  1. added this to the needsTriage milestone on Sep 17, 2025
  2. leonsenft commented on Sep 17, 2025

    @leonsenft
    ContributorAuthor

    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.

  3. JeanMeche commented on Sep 17, 2025

    @JeanMeche
    Member

    The issue here is that Field is not an array but an iterable and the reconcilation algorithm treats them differently.

    cc @pkozlowski-opensource

  4. leonsenft commented on Sep 17, 2025

    @leonsenft
    ContributorAuthor

    The issue here is that Field is not an array but an iterable and the reconcilation algorithm treats them differently.

    I think this is one half of the issue. The other half has to do with how the form() internally creates Field instances for individual array elements.

  5. mmalerba commented on Nov 13, 2025

    @mmalerba
    Contributor

    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

  6. angular-automatic-lock-bot commented on Dec 14, 2025

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions