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: amp-ad clean up intersectionObserver timeout #4233

Merged
merged 3 commits into from Jul 28, 2016

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jul 27, 2016

Add presubmit check for scheduleUnlayout function
scheduleUnlayout for ad when user close sticky-ad
Check element inside document before in intersectionObserver flush_ function, fix tests.
follow up #4035

@@ -218,10 +223,18 @@ export class IntersectionObserver extends Observable {
}

/**
* Provice a function to clear timeout before set this intersection to null.
* Provide a function to clear timeout before set this intersection to null.
*/
destroy() {
timer.cancel(this.flushTimeout_);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed that we do this.baseElement_.getViewport().onScroll above and such. Should we unlisten them as well here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume there's no need, because in every scenario where we call destory() we would have already set the baseElement viewportCallback(false), and the intersectionObserver onViewportCallback(false) would unlisten them for us.
https://github.com/ampproject/amphtml/blob/master/src/intersection-observer.js#L176

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 still go ahead and call onViewportCallback(false) in destroy for double tap (https://www.youtube.com/watch?v=HQe2f8L-Rkc)

@dvoytenko
Copy link
Contributor

LGTM

},
'scheduleUnlayout': {
message: bannedTermsHelpString,
whitelist: [
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of whitelisting, let's use /*OK*/ where it's called.

if (this.unlistenViewportChanges_) {
this.unlistenViewportChanges_();
this.unlistenViewportChanges_ = null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't call onViewportCallback(false) because I don't want to call fire() in destroy() function, but I did add the double tap that check onScroll and onChange listener are unlistened.
Nice Video BTW!
@dvoytenko

@zhouyx
Copy link
Contributor Author

zhouyx commented Jul 27, 2016

@jridgewell PTAL

*/
destroy() {
timer.cancel(this.flushTimeout_);
this.flushTimeout_ = 0;
if (this.unlistenViewportChanges_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this into it's own method, so we don't have the duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, Add unlistenOnOutViewport_ method

@zhouyx
Copy link
Contributor Author

zhouyx commented Jul 27, 2016

I remove the isInDoc check. Two reasons:

  1. we are not getting errors even we don't have it right now.
  2. I still don't know how expensive the check is, (should be cheap though) I don't want to add the check for some super rare cases.

I put a TODO comment there. It would be a good place to check in the future.

@dvoytenko @jridgewell

@jridgewell
Copy link
Contributor

LGTM.

@zhouyx zhouyx merged commit 71736b8 into ampproject:master Jul 28, 2016
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
@zhouyx zhouyx deleted the unlayout-ad branch September 28, 2016 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants