Skip to content

fix(core): make DefaultIterableDiffer keep the order of duplicates#23941

Closed
csr632 wants to merge 1 commit intoangular:masterfrom
csr632:fix-DefaultIterableDiffer-mismatch
Closed

fix(core): make DefaultIterableDiffer keep the order of duplicates#23941
csr632 wants to merge 1 commit intoangular:masterfrom
csr632:fix-DefaultIterableDiffer-mismatch

Conversation

@csr632
Copy link
Copy Markdown
Contributor

@csr632 csr632 commented May 16, 2018

Previously, in _mismatch, DefaultIterableDiffer first check _linkedRecords for itemTrackBy, then check _unlinkedRecords.
This cause DefaultIterableDiffer match itemTrackBy with the "later" duplicate in the old collection, rather than the "preceding" one.
Now we check _unlinkedRecords first, so that DefaultIterableDiffer can give more simple and reasonable info after diffing:
a1 b c a2 => b a1 c a2 (a1 and a2 have same trackById)
See the new test case in default_iterable_differ_spec.ts and #23815.

Fix #23815

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] angular.io application / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #23815

What is the new behavior?

DefaultIterableDiffer can give more simple and reasonable info after diffing a1 b c a2 => b a1 c a2 (a1 and a2 have same trackById). See #23815 .

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@csr632 csr632 force-pushed the fix-DefaultIterableDiffer-mismatch branch 2 times, most recently from 16b3875 to 6e1bac1 Compare May 16, 2018 16:36
@csr632 csr632 force-pushed the fix-DefaultIterableDiffer-mismatch branch from 6e1bac1 to 8284a0f Compare May 28, 2018 15:22
@vicb vicb added the area: core Issues related to the framework runtime label May 31, 2018
@csr632
Copy link
Copy Markdown
Contributor Author

csr632 commented Jun 22, 2018

What do you guys think about this?

@jasonaden jasonaden added this to the needsTriage milestone Jan 29, 2019
@pullapprove pullapprove bot requested a review from alxhub March 22, 2020 08:57
@petebacondarwin petebacondarwin self-assigned this Jan 26, 2021
@petebacondarwin petebacondarwin self-requested a review January 26, 2021 18:57
Previously, in `_mismatch()`, the `DefaultIterableDiffer` first checks
`_linkedRecords` for `itemTrackBy`, then checks `_unlinkedRecords`.
This cause the `DefaultIterableDiffer` to move "later" items that match the
`itemTrackBy` from the old collection, rather than using the "earlier" one.

Now we check `_unlinkedRecords` first, so that the `DefaultIterableDiffer`
can give a more stable and reasonable result after diffing. For example,
rather than (`a1` and `a2` have same trackById)

```
a1 b c a2 => b a2 c a1
```

we get

```
a1 b c a2 => b a1 c a2
```

where a1 and a2 retain their original order despite both
having the same track by value.

Fixes angular#23815
@petebacondarwin petebacondarwin force-pushed the fix-DefaultIterableDiffer-mismatch branch from 8284a0f to 9abb073 Compare January 26, 2021 19:12
@petebacondarwin
Copy link
Copy Markdown
Contributor

I rebased to resolve the conflicts and tweaked the commit message slightly.

@petebacondarwin petebacondarwin requested review from AndrewKushnir and removed request for alxhub January 26, 2021 19:13
@petebacondarwin petebacondarwin added action: presubmit The PR is in need of a google3 presubmit action: review The PR is still awaiting reviews from at least one requested reviewer labels Jan 26, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jan 26, 2021
@petebacondarwin petebacondarwin added the target: minor This PR is targeted for the next minor release label Jan 26, 2021
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Jan 26, 2021

presubmit

@AndrewKushnir AndrewKushnir removed their request for review January 26, 2021 20:03
@petebacondarwin petebacondarwin removed their request for review January 26, 2021 20:26
@petebacondarwin petebacondarwin removed their assignment Jan 26, 2021
@mhevery mhevery added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release and removed action: presubmit The PR is in need of a google3 presubmit labels Jan 26, 2021
@mhevery mhevery removed action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Jan 26, 2021
@angular-automatic-lock-bot
Copy link
Copy Markdown

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 Feb 26, 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 area: core Issues related to the framework runtime cla: yes core: differs target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DefaultIterableDiffer should keep the order of duplicates

8 participants