Skip to content

@for(ID of IDs; track ID) and NG0956 - provide a way to prevent warning when tracking by item is legit scenario #56471

Description

@montella1507

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

core

Is this a regression?

Yes

Description

We are rendering nodes:

@for(id of ids; track id) {
 <node [id]="id"/>
}
image

But we are getting NG0956 warning:
...and make sure that it uniquely identifies items in a collection

I understood is it usually not good idea to track collection nodes by themselves.

However, this is exception, because collection is list of IDs of the nodes and "ID" is unique identifier of the node.

Please reconsider the warning. I think the framework should have not thrown this warning if the element of the collection may be unique key (maybe it should throw this warning only when "id" is object and not string / number)

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

NG0956: The configured tracking expression (track by identity) caused re-creation of the entire collection of size 1. This is an expensive operation requiring destruction and subsequent creation of DOM nodes, directives, components etc. Please review the "track expression" and make sure that it uniquely identifies items in a collection. Find more at https://angular.io/errors/NG0956

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

Angular CLI: 18.0.1
Node: 20.9.0
Package Manager: yarn 1.22.19
OS: darwin arm64

Angular: 18.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.1
@angular-devkit/build-angular   18.0.1
@angular-devkit/core            18.0.1
@angular-devkit/schematics      18.0.1
@angular/cli                    18.0.1
@schematics/angular             18.0.1
ng-packagr                      18.0.0
rxjs                            7.8.1
typescript                      5.4.5
webpack                         5.89.0
zone.js                         0.14.6

Anything else?

...or just provide a way how to halt / mute this warning.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: coreIssues related to the framework runtimecore: control flowIssues related to the built-in control flow (@if, @for, @switch)

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions