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

check amp-ad iframe_ is null #3670

Merged
merged 2 commits into from Jun 21, 2016
Merged

Conversation

zhouyx
Copy link
Contributor

@zhouyx zhouyx commented Jun 20, 2016

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 20, 2016

@erwinmombay @cramforce @jridgewell PTAL

@@ -394,7 +398,7 @@ class AmpAd extends AMP.BaseElement {
this.toggleFallback(true);
}
// Remove the iframe only if it is not the master.
if (this.iframe_.name.indexOf('_master') == -1) {
if (this.iframe_ && this.iframe_.name.indexOf('_master') == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What should be the desired state here? If the user navigates back to this tab, they may see the fallback element now whereas usually we would try loading another ad.

Copy link
Contributor Author

@zhouyx zhouyx Jun 20, 2016

Choose a reason for hiding this comment

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

I don't see why checking this.iframe_ is not null here would change behaviors when user navigates back.
Here's what I understand, the only reason this.iframe_ is null here is that it's set in unlayoutCallback() before. And if that's the case we don't need to call removeElement and setthis.iframe_ = null here. Also we are not doing anything when this.iframe_ = null here before, so adding the extra check here shouldn't change anything?

Copy link
Member

Choose a reason for hiding this comment

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

This just happens if we killed the iframe in the last animation frame. I think this is exactly correct.

One option would be to short circuit the entire callback by if (!this.iframe_) since nothing here makes sense without it.

@cramforce
Copy link
Member

LGTM

@zhouyx
Copy link
Contributor Author

zhouyx commented Jun 21, 2016

Check iframe null and skip noContentHandler callback. PTAL

@cramforce
Copy link
Member

LGTM

@@ -379,6 +382,10 @@ class AmpAd extends AMP.BaseElement {
* @private
*/
noContentHandler_() {
// If iframe is null nothing to do.
Copy link
Contributor

Choose a reason for hiding this comment

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

This still leaves us open to the deferred issue. If the ad calls #noContentHandler_ then the ad is unloaded, it will try to access the iframe's name and the iframe is null.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right. The same checks needs to be done at the start of the deferMutate callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woops. Thanks @jridgewell for pointing this out! added check in deferMuate

@jridgewell
Copy link
Contributor

LGTM.

@zhouyx zhouyx merged commit 19173c1 into ampproject:master Jun 21, 2016
@zhouyx zhouyx deleted the iframe-null-issue branch June 21, 2016 23:39
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

4 participants