Skip to content
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(core): viewport trigger deregistering callbacks multiple times #52115

Closed

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Oct 9, 2023

Adds a check to the viewport cleanup function to prevent it from re-processing elements that have been fully cleaned up, because it can lead to the IntersectionObserver being destroyed even though there are still pending triggers. This can happen, because we have cleanup callbacks both for the block is loaded, but also when the placeholder view is destroyed.

Fixes #52113.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Oct 9, 2023
@crisbeto crisbeto added this to the v17-candidates milestone Oct 9, 2023
@@ -176,6 +176,11 @@ class DeferIntersectionManager {
entry.callbacks.add(callback);

return () => {
// It's possible that a different cleanup callback fully removed this element already.
if (!this.viewportTriggers.has(trigger)) {
Copy link
Member

Choose a reason for hiding this comment

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

You could save some bytes using

if (!entry!.callbacks.delete(callback)) {
  return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

(I'd like to ask for a small comment in the code above the if in this case :))

@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 9, 2023
@pkozlowski-opensource pkozlowski-opensource added the core: defer Issues related to @defer blocks. label Oct 10, 2023
Adds a check to the viewport cleanup function to prevent it from re-processing elements that have been fully cleaned up, because it can lead to the `IntersectionObserver` being destroyed even though there are still pending triggers. This can happen, because we have cleanup callbacks both for the block is loaded, but also when the placeholder view is destroyed.

Fixes angular#52113.
@crisbeto crisbeto force-pushed the 52113/viewport-cleanup-multiple branch from eac8cce to 0efeb20 Compare October 10, 2023 09:12
@crisbeto
Copy link
Member Author

I found a way to capture it in a test.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Oct 10, 2023
@crisbeto
Copy link
Member Author

Caretaker note: the CI is passing, but it's not green because the CI is referring to a check that doesn't exist.

@angular-robot
Copy link
Contributor

angular-robot bot commented Oct 10, 2023

This PR was merged into the repository by commit d5dad3e.

@angular-robot angular-robot bot closed this in d5dad3e Oct 10, 2023
crisbeto added a commit to crisbeto/angular that referenced this pull request Oct 11, 2023
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed angular#52115 so now we can switch back to the previous approach which is a bit more compact.
crisbeto added a commit to crisbeto/angular that referenced this pull request Oct 11, 2023
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed angular#52115 so now we can switch back to the previous approach which is a bit more compact.
crisbeto added a commit to crisbeto/angular that referenced this pull request Oct 12, 2023
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed angular#52115 so now we can switch back to the previous approach which is a bit more compact.
pkozlowski-opensource pushed a commit that referenced this pull request Oct 13, 2023
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed #52115 so now we can switch back to the previous approach which is a bit more compact.

PR Close #52156
pkozlowski-opensource pushed a commit that referenced this pull request Oct 13, 2023
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed #52115 so now we can switch back to the previous approach which is a bit more compact.

PR Close #52156
@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 Nov 11, 2023
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…ngular#52115)

Adds a check to the viewport cleanup function to prevent it from re-processing elements that have been fully cleaned up, because it can lead to the `IntersectionObserver` being destroyed even though there are still pending triggers. This can happen, because we have cleanup callbacks both for the block is loaded, but also when the placeholder view is destroyed.

Fixes angular#52113.

PR Close angular#52115
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
When the `viewport` triggers were first introduced, we ended up having to use a service to keep track of them, because using the same global event handling as the other events led to some inconsistent test failures. It looks like the failures were caused by the same bug fixed angular#52115 so now we can switch back to the previous approach which is a bit more compact.

PR Close angular#52156
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: defer Issues related to @defer blocks. merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

defer viewport doesn't work as expected
4 participants