-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(common): throw an error if trackBy is not a function #13420
Conversation
8156b5e
to
2e0dd9a
Compare
@Input() ngForTrackBy: TrackByFn; | ||
@Input() | ||
set ngForTrackBy(fn: TrackByFn) { | ||
if (typeof fn !== 'function') { |
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.
if (fn && typeof fn !== 'function') {
}
Would be consistent with the differ:
constructor(private _trackByFn?: TrackByFn) {
this._trackByFn = this._trackByFn || trackByIdentity;
}
a3636f9
to
6022416
Compare
every day http://prntscr.com/dk3j70 |
@mhevery @IgorMinar wdyt ? See the original issue also. |
@Input() ngForTrackBy: TrackByFn; | ||
@Input() | ||
set ngForTrackBy(fn: TrackByFn) { | ||
console.log('input', fn); |
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.
console.log
leftover.
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.
it was for debugging purposes :)
set ngForTrackBy(fn: TrackByFn) { | ||
console.log('input', fn); | ||
if (fn && typeof fn !== 'function') { | ||
console.log('inside', fn); |
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.
console.log
leftover.
`<template ngFor let-item [ngForOf]="items" [ngForTrackBy]="item?.id"></template>`; | ||
fixture = createTestComponent(template); | ||
|
||
console.log('1'); |
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.
console.log
leftover.
console.log('1'); | ||
fixture.detectChanges(); | ||
// expect(() => fixture.detectChanges()) | ||
// .toThrowError(/trackBy must be a function, but received 1/); |
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.
expectation commented out...
|
||
console.log('1'); | ||
getComponent().items = [{id: 1}, {id: 2}]; | ||
console.log('1'); |
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.
console.log
leftover.
I agree with @DzmitryShylovich that this is very common mistake people do and it fails silently so having some kind of check would improve ergonomics. Having said this I've removed "LGTM" label as beside the decision this PR needs serious cleanup :-) |
78d7865
to
6c60fce
Compare
done 😄 |
We all agree that the check is needed here. I should have given more context: The question here is should |
This LGTM. I think we should throw if it is
|
) * fix(common): throw an error if trackBy is not a function Closes angular#13388 * refactor(platform-browser): disable no-console rule in DomAdapter
…ect usages of trackBy
…rect usages of trackBy
…ect usages of trackBy Added note about angular#13420 to the CHANGELOG, which affects incorrect usages of trackBy
…ect usages of trackBy Added note about angular#13420 to the CHANGELOG, which affects incorrect usages of trackBy
…ch affects incorrect usages of trackBy
Reverts a breaking change introduced in 2.4.1 by angular#13420 fixes angular#13641
Reverts a breaking change introduced in 2.4.1 by angular#13420 fixes angular#13641
Reverts a breaking change introduced in 2.4.1 by angular#13420 fixes angular#13641
Reverts a breaking change introduced in 2.4.1 by angular#13420 fixes angular#13641
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #13388