Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 12, 2020

The virtual scroll only creates its IterableDiffer once, which means that if the trackBy function comes in at a later point (e.g. the input changed or the initialization order is different), it won't be picked up.

These changes make it so the differ always has a trackBy which then delegates to the user-provided one or falls back to the default.

Fixes #21281.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Dec 12, 2020
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 12, 2020
@Input() items = Array(10).fill(0).map((_, i) => i);
@Input() trackBy: TrackByFunction<number>;
@Input() templateCacheSize = 20;
orientation = 'vertical';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the Input here isn't necessary for the fix, but I noticed that they don't actually do anything.

@crisbeto crisbeto changed the title fix(cdk/scrolling): virtual scroll not picking up trackBy function wh… fix(cdk/scrolling): virtual scroll not picking up trackBy function when items come in after init Dec 12, 2020
…en items come in after init

The virtual scroll only creates its `IterableDiffer` once, which means that if the
`trackBy` function comes in at a later point (e.g. the input changed or the
initialization order is different), it won't be picked up.

These changes make it so the differ always has a `trackBy` which then delegates
to the user-provided one or falls back to the default.

Fixes angular#21281.
@crisbeto crisbeto force-pushed the 21281/track-by-delayed branch from a815ad9 to 709691d Compare December 13, 2020 11:40
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Dec 14, 2020
@mmalerba mmalerba merged commit 43081d9 into angular:master Dec 17, 2020
mmalerba pushed a commit that referenced this pull request Dec 17, 2020
…en items come in after init (#21335)

The virtual scroll only creates its `IterableDiffer` once, which means that if the
`trackBy` function comes in at a later point (e.g. the input changed or the
initialization order is different), it won't be picked up.

These changes make it so the differ always has a `trackBy` which then delegates
to the user-provided one or falls back to the default.

Fixes #21281.

(cherry picked from commit 43081d9)
wagnermaciel pushed a commit to wagnermaciel/components that referenced this pull request Jan 14, 2021
…en items come in after init (angular#21335)

The virtual scroll only creates its `IterableDiffer` once, which means that if the
`trackBy` function comes in at a later point (e.g. the input changed or the
initialization order is different), it won't be picked up.

These changes make it so the differ always has a `trackBy` which then delegates
to the user-provided one or falls back to the default.

Fixes angular#21281.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(cdkVirtualFor): cdkVirtualFor doesn't use trackBy if is rendered after cdk-virtual-scroll-viewport

2 participants