Skip to content

fix(core): properly update collection with repeated keys in @for#52697

Closed
pkozlowski-opensource wants to merge 1 commit intoangular:mainfrom
pkozlowski-opensource:control_flow_52524
Closed

fix(core): properly update collection with repeated keys in @for#52697
pkozlowski-opensource wants to merge 1 commit intoangular:mainfrom
pkozlowski-opensource:control_flow_52524

Conversation

@pkozlowski-opensource
Copy link
Copy Markdown
Member

This change fixes a bug in the new list reconcilation algorithm that could lead to an infinite loop in certain situations.

More specifically, it adjusts the internal MultiMap implementation such that an entry returned from the .get call is the same entry (for an identical key) removed by the .delete call.

The existing logic of the MultiMap was leading to a situation where one view was requested and attached to LContainer, but a very different view was removed from the MultiMap. This was leaving an attached LView in a collection that was supposed to hold only detached views.

Closes #52524

This change fixes a bug in the new list reconcilation algorithm
that could lead to an infinite loop in certain situations.

More specifically, it adjusts the internal MultiMap implementation
such that an entry returned from the .get call is the same entry
(for an identical key) removed by the .delete call.

The existing logic of the MultiMap was leading to a situation where
one view was requested and attached to LContainer, but a very different
view was removed from the MultiMap. This was leaving an attached LView
in a collection that was supposed to hold only detached views.

Closes angular#52524
@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release labels Nov 8, 2023
@ngbot ngbot bot modified the milestone: Backlog Nov 8, 2023
@pkozlowski-opensource pkozlowski-opensource added the core: control flow Issues related to the built-in control flow (@if, @for, @switch) label Nov 8, 2023
imports: [ChildCmp],
template: `
@for(task of tasks; track task.id) {
<child-cmp/>
Copy link
Copy Markdown
Member

@JoostK JoostK Nov 8, 2023

Choose a reason for hiding this comment

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

Is the child comp needed, instead of doing e.g. |{{ task.name }}|? We could then have an assertion that the textContent has been updated to reflect the reordering + deletion accurately, and I'd expect the additional component to be irrelevant for the test (the embedded views get out of sync, not the component view?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The child component is need to show that the "wrong" view is attached and corrupts LView / Container data structures. I couldn't reproduce the app freeze without a child component view.

We could then have an assertion that the textContent has been updated to reflect the reordering + deletion accurately

This would introduce an assumption about the order of views with duplicated keys and I would rather not do it at this point. Unless I'm misunderstanding the idea of an alternative test...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, interesting! I wouldn't have expected that.

My thinking behind the assertion was that it would verify that the list updates have been properly reflected in the DOM. The items with the same ID also have the same name, so they could be reordened at will without problem.

@pkozlowski-opensource pkozlowski-opensource added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 9, 2023
@jessicajaniuk
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit ea8c9b6.

jessicajaniuk pushed a commit that referenced this pull request Nov 9, 2023
)

This change fixes a bug in the new list reconcilation algorithm
that could lead to an infinite loop in certain situations.

More specifically, it adjusts the internal MultiMap implementation
such that an entry returned from the .get call is the same entry
(for an identical key) removed by the .delete call.

The existing logic of the MultiMap was leading to a situation where
one view was requested and attached to LContainer, but a very different
view was removed from the MultiMap. This was leaving an attached LView
in a collection that was supposed to hold only detached views.

Closes #52524

PR Close #52697
@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 Dec 10, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…ular#52697)

This change fixes a bug in the new list reconcilation algorithm
that could lead to an infinite loop in certain situations.

More specifically, it adjusts the internal MultiMap implementation
such that an entry returned from the .get call is the same entry
(for an identical key) removed by the .delete call.

The existing logic of the MultiMap was leading to a situation where
one view was requested and attached to LContainer, but a very different
view was removed from the MultiMap. This was leaving an attached LView
in a collection that was supposed to hold only detached views.

Closes angular#52524

PR Close angular#52697
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 core: control flow Issues related to the built-in control flow (@if, @for, @switch) target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For loops in new control flow are extremely slow and taking much more memory than ngFor

4 participants