-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ngRepeat): fix trackBy function being invoked with incorrect scope #16777
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
For future reference, this was broken in bdd853c. |
0070020
to
5819a21
Compare
This also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
Also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
src/ng/directive/ngRepeat.js
Outdated
|
||
// Clear the value property from the hashFnLocals object to prevent a reference to the last value | ||
// being leaked into this ngRepeatCompile function scope | ||
hashFnLocals[valueIdentifier] = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about clearing the value here? This way we don't have to touch the trackByIdExpFn
method that gets invoked on each element and just add this one assignment at the end.
src/ng/directive/ngRepeat.js
Outdated
// Clear the value property from the hashFnLocals object to prevent a reference to the last value | ||
// being leaked into this ngRepeatCompile function scope | ||
if (hashFnLocals) { | ||
hashFnLocals[valueIdentifier] = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about keyIdentifier
? Can't is be non-primitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keyIdentifier
value is either an index or the itemKey
from for (var itemKey in collection)
. So it should always be a number or string.
The build is all green 😲 |
Also fixes a leak of that scope across all further instances of the repeated element. Fixes angular#16776 Closes angular#16777
I rebased just to add "Ref #16776" to the second commit message, and got the build green again! |
This also fixes a leak of that scope across all further instances of the
repeated element.
Fixes #16776
What is the current behavior? (You can also link to an open issue here)
The track-by function would get created on the first linking of an
ng-repeat
and then get cached forever, so each time thatng-repeat
was re-linked (when it is repeated, or destroyed+recreated viang-if
etc.) the previous scope would be used. This also "leaks" the scope for the lifetime of that compiled node.What is the new behavior (if this is a feature change)?
The track-by no longer directly references the scope