Visitar URL original
signal-forms: Field value change signals update frequently · Issue #63627 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20250916014241/https://github.com/angular/angular/issues/63627
Skip to content

signal-forms: Field value change signals update frequently #63627

@ThiloAschebrock

Description

@ThiloAschebrock

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

Consider the following example with a signal form of two independent fields. Of those, the first field's value is logged using an effect that is accessing this.form.first().value():

@Component({
  selector: 'app-root',
  imports: [Control],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <input [control]="form.first"/>
    <input [control]="form.second"/>
  `,
})
export class App {
  readonly form = form(signal({ first: '', second: '' }));

  readonly logFirstEffect = effect(() => {
    console.log(this.form.first().value());
  });
}

Notice that when typing in the second control, the effect still fires. This is because this.form.first() is re-computed.

For me, this was initially unexpected, and caused an infinite effect, when trying to conditional sync form values, which is a feature you seem willing to provide a native solution for in [Design] fields whose value is sometimes computed from other fields.

One can, of course, circumvent this issue by memorising the value as

readonly firstValue = computed(() => this.form.first().value())

As there is a general need to listen to individual field value changes in the spirit of valueChanges offered by reactive forms, be it via an effect or a computed signal, could you please consider on of the following:

  1. Optimize the value updates so that they are not triggered on unrelated changes.
  2. Expose field value changes via a different API that only updates when underlying value changes.
  3. Document this potential pitfall explicitly within your upcoming documentation.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-46vthvkl?file=src%2Fmain.ts

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 21.0.0-next.2
Node: 20.19.1
Package Manager: npm 10.8.2
OS: linux x64
    

Angular: 21.0.0-next.2
... build, cli, common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                      Version
------------------------------------
@angular-devkit/architect    0.2100.0-next.2
@angular-devkit/core         21.0.0-next.2
@angular-devkit/schematics   21.0.0-next.2
@schematics/angular          21.0.0-next.2
rxjs                         7.8.2
typescript                   5.9.2

Anything else?

This might just be an observation and possible area of optimisation that you already aware of and addressing as part of [Optimize] Value updates and recomputation of childrenMap.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions