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(ID of IDs; track ID) and NG0956 - provide a way to prevent warning when tracking by item is legit scenario #56471
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"/>
}
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)
...or just provide a way how to halt / mute this warning.
Reacted by Rokas Brazdžionis, Silvermind, OWEN KELVIN OTIENO, az, Evgeny Stepanovych, Reid Greer, Jef, Hadi Kashlan, slimache, Anders Bergquist and 26 more
Reacted by fonlow, John Fred Fadrigalan and Daniel Haupt
changed the title [-]@for(ID of IDs; track ID) and NG0956[/-][+]@for(ID of IDs; track ID) and NG0956 - do not show warning when collection is tracked by collection items of primitive type[/+]on Jun 16, 2024
changed the title [-]@for(ID of IDs; track ID) and NG0956 - do not show warning when collection is tracked by collection items of primitive type[/-][+]@for(ID of IDs; track ID) and NG0956 - provide a way to prevent warning when tracking by item is legit scenario[/+]on Jun 16, 2024
We are still trying to decide on the best API for opting out of this warning for the legitimate cases where a given collection needs to be re-created. For now a work-around is to create an identity method on a component: https://stackblitz.com/edit/stackblitz-starters-ytmizy?file=src%2Fmain.ts
This is not the most ergonomic way, but this is what we've got right now.
In my case, I have a TableComponent which is used to display any kind of Array throughout the application. And there are hundreds of places where this is used.
In almost all cases, I will fetch data from backend and the result will be saved to a property in the page-component which is then used to send into the TableComponent through @input rows: Array
For example. in CustomersComponent, this is stripped down to what is fetched from backend.
Every time I will do any kind of action that will trigger CustomerComponent to fetch data from server, the warning about recreating is shown.
This is where I don't really see why I get the warning. I want the table to recreate all the rows because I got a new collection from backend.
So, to avoid the warning, I see 2 different solutions.
First one is to provide my TableComponent with information what property of a row-object is to be considered unique.
In my example of Customers, the unique property would be customerNumber.
The down side is that I would need to go through hundreds of places and explicitly say "this is the unique field".
The second option, generate a unique value of the row-object.
@for (row of rows; track trackRowsBy(row); let i = $index) {
The question here would be, how much of a performance impact would the second option result in.
I have a pretty strict pagination strategy so I will seldom show more than 50 rows at the same time.
However, would it be considered bad design to generate a unique id of the data in regards to performance?
Another case where the detection may be too sensitive:
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.dev/errors/NG0956
entire collection of size 1 If the collection changes and is of size 1, yes, indeed that will be the entire collection.
Also there are cases where we want to change the entire collection (when paginating display mostly, it makes sense to recreate the dom to avoid weird user state being kept).
Reacted by Benjamin Lee, Philip Dakowitz and packone
My problem with this error message, apart from seeing too many of them, is I have no idea where the error is coming from. ɵɵrepeater | @ | core.mjs:27348 tells me nothing about where in my own code I should be trying to hunt down the issue. Please include the HTML file and line number, if possible, or at least a little more detail like the track-by identifier.
My problem with this error message, apart from seeing too many of them, is I have no idea where the error is coming from. ɵɵrepeater | @ | core.mjs:27348 tells me nothing about where in my own code I should be trying to hunt down the issue. Please include the HTML file and line number, if possible, or at least a little more detail like the track-by identifier.
Expand the stack trace in the console to see which template the error originates.
Expand the stack trace in the console to see which template the error originates.
I've done that, and there's nothing useful in the stack trace. Just references to Angular internals, nothing referencing my own code or my own templates.
My use case is this: An item is a message generated by the protobuf compiler. It doesn't have a unique id that I could use to identify it. I use identification by identity because that's the way it's supposed to be.
My understanding is that I should create a protected method that just returns the item to opt-out, but it doesn't look too nice. I would appreciate a better way.
And not only that completely ridiculous to throw hundreds of that same warning every time. Without any information about it. Lets assume you got a component and use it 10 times, got a @for in it, with 100 items, well your devtools crashes every time, because of the overflow.
Reacted by Igor Motovilov, Tobivaria, Edoardo Luppi, Daniel Jackson and packone
Activity
[-]@for(ID of IDs; track ID) and NG0956[/-][+]@for(ID of IDs; track ID) and NG0956 - do not show warning when collection is tracked by collection items of primitive type[/+][-]@for(ID of IDs; track ID) and NG0956 - do not show warning when collection is tracked by collection items of primitive type[/-][+]@for(ID of IDs; track ID) and NG0956 - provide a way to prevent warning when tracking by item is legit scenario[/+]JeanMeche commentedon Jun 17, 2024
Hi, could try to produce a narrowed down repro ?
What is the type of
id?montella1507 commentedon Jun 17, 2024
https://stackblitz.com/edit/stackblitz-starters-1qz55n?file=src%2Fmain.ts
Here.
schema().children is computed signal. ID is of type string.
Signal store is not needed to simulate this warning. However, maybe computed/signals are.
JeanMeche commentedon Jun 17, 2024
I can be narrowed down to this : Updating the array by keeping the same size but replacing all values.
pkozlowski-opensource commentedon Jun 20, 2024
We are still trying to decide on the best API for opting out of this warning for the legitimate cases where a given collection needs to be re-created. For now a work-around is to create an identity method on a component: https://stackblitz.com/edit/stackblitz-starters-ytmizy?file=src%2Fmain.ts
This is not the most ergonomic way, but this is what we've got right now.
montella1507 commentedon Aug 30, 2024
Hello, any news?
Socratezz commentedon Sep 30, 2024
Another vote for this a month later. Any updates?
andersb commentedon Oct 22, 2024
Just ran into this issue.
In my case, I have a TableComponent which is used to display any kind of Array throughout the application. And there are hundreds of places where this is used.
In almost all cases, I will fetch data from backend and the result will be saved to a property in the page-component which is then used to send into the TableComponent through @input rows: Array
For example. in CustomersComponent, this is stripped down to what is fetched from backend.
Every time I will do any kind of action that will trigger CustomerComponent to fetch data from server, the warning about recreating is shown.
This is where I don't really see why I get the warning. I want the table to recreate all the rows because I got a new collection from backend.
So, to avoid the warning, I see 2 different solutions.
First one is to provide my TableComponent with information what property of a row-object is to be considered unique.
In my example of Customers, the unique property would be customerNumber.
The down side is that I would need to go through hundreds of places and explicitly say "this is the unique field".
The second option, generate a unique value of the row-object.
which is then used
@for (row of rows; track trackRowsBy(row); let i = $index) {The question here would be, how much of a performance impact would the second option result in.
I have a pretty strict pagination strategy so I will seldom show more than 50 rows at the same time.
However, would it be considered bad design to generate a unique id of the data in regards to performance?
zijianhuang commentedon Oct 27, 2024
Yes, I have legitimate cases too:
And the lookup by id is through a local dictionary.
According to https://angular.dev/errors/NG0956, the rule is focused on the nominated scenario with the todo list.
In my scenario, an article (data) is associated with many annotations which are shared by article objects.
c-harding commentedon Nov 19, 2024
@pkozlowski-opensource I found an even more light-weight workaround, when working with strings: append the empty string.
mihli-hf commentedon Dec 23, 2024
Any update on this issue ?
JeanRemiDelteil commentedon Jan 29, 2025
Another case where the detection may be too sensitive:
entire collection of size 1If the collection changes and is of size 1, yes, indeed that will be the entire collection.Also there are cases where we want to change the entire collection (when paginating display mostly, it makes sense to recreate the dom to avoid weird user state being kept).
kshetline commentedon Mar 11, 2025
My problem with this error message, apart from seeing too many of them, is I have no idea where the error is coming from.
ɵɵrepeater | @ | core.mjs:27348tells me nothing about where in my own code I should be trying to hunt down the issue. Please include the HTML file and line number, if possible, or at least a little more detail like the track-by identifier.JoostK commentedon Mar 12, 2025
Expand the stack trace in the console to see which template the error originates.
kshetline commentedon Mar 13, 2025
I've done that, and there's nothing useful in the stack trace. Just references to Angular internals, nothing referencing my own code or my own templates.
zyv commentedon Apr 8, 2025
My use case is this: An
itemis a message generated by theprotobufcompiler. It doesn't have a unique id that I could use to identify it. I use identification by identity because that's the way it's supposed to be.https://github.com/rdamazio/efis-editor/blob/355803d3be1f8c093fea6cec4d8c8dd9ca3feb34/src/app/checklists/items-list/items-list.component.html#L14
My understanding is that I should create a protected method that just returns the item to opt-out, but it doesn't look too nice. I would appreciate a better way.
fix(app): suppress NG0956 warning - angular/angular#56471
fix(app): suppress NG0956 warning - angular/angular#56471
egonknapen commentedon May 31, 2025
And not only that completely ridiculous to throw hundreds of that same warning every time. Without any information about it. Lets assume you got a component and use it 10 times, got a @for in it, with 100 items, well your devtools crashes every time, because of the overflow.
m-thompson-code commentedon Aug 21, 2025
its upsetting that this is kind of the cleaning way of dealing with this issue for string arrays. :( can this issue be fixed soon? Seems silly