-
Notifications
You must be signed in to change notification settings - Fork 35
Description
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
this happens because of this loop i think:
we track there on "op" which is a Select2Option (so a complete javascript object)
if i look at the actual angular samples in this link: https://angular.dev/errors/NG0956
then it is pretty much exactly the same problem the for loop loops over a big js object:
@for (op of selectedOption || []; track op) {
and tracks on that but they say you should do something like
@for (op of selectedOption || []; track op.id) {
which is then a primitive object..
now Select2Option does have an id:
but that doesn't seem to be set, i think the label and the value are mandatory so should that track not be
@for (op of selectedOption || []; track op.value) {
and the value is of type Select2Value which is just a synoniem for a primitive for the most part. (doesn't have to be but i think its just like that for most cases)
there are 2 more of those loops first is:
@for (groupOrOption of filteredData(); track groupOrOption; let i = $index)
but that groupOrOption is a Select2Data which is a Select2Group | Select2Option and those only have label i think in common..
the 3rd is
@for (option of group.options; track option; let j = $index) {
which is a Select2Option again so that can be tracked by the option.value i think