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

Revert owner lifecycle control from the amp-iframe #32541

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions extensions/amp-iframe/0.1/amp-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,6 @@ export class AmpIframe extends AMP.BaseElement {
}
}

/** @override */
unlayoutOnPause() {
return true;
}

/**
* @param {boolean} isDisplayed
* @private
Expand All @@ -645,8 +640,7 @@ export class AmpIframe extends AMP.BaseElement {
return;
}
this.isDisplayed_ = isDisplayed;
const hasOwner = !!this.element.getOwner();
if (!isDisplayed && !hasOwner && this.iframe_) {
if (!isDisplayed && this.iframe_) {
this.getVsync().mutate(() => this.unload());
}
}
Expand Down
26 changes: 3 additions & 23 deletions extensions/amp-iframe/0.1/test/test-amp-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ describes.realWin(
const impl = await ampIframe.getImpl(false);
await waitForAmpIframeLayoutPromise(doc, ampIframe);
expect(ampIframe.querySelector('iframe')).to.exist;
expect(ampIframe.unlayoutOnPause()).to.be.true;
expect(ampIframe.unlayoutOnPause()).to.be.false;

// The element should become visible before pause is necessary.
setDisplay(ampIframe, true);
Expand All @@ -1101,26 +1101,6 @@ describes.realWin(
expect(impl.unload).to.be.calledOnce;
});

it('should not unlayout on pause if has owner', async () => {
const ampIframe = createAmpIframe(env, {
src: iframeSrc,
width: 100,
height: 100,
});
const impl = await ampIframe.getImpl(false);
impl.element.getOwner = () => ({});
await waitForAmpIframeLayoutPromise(doc, ampIframe);
expect(ampIframe.querySelector('iframe')).to.exist;
expect(ampIframe.unlayoutOnPause()).to.be.true;

setDisplay(ampIframe, true);
setDisplay(ampIframe, false);
env.sandbox.stub(impl, 'unload');

await new Promise(setTimeout);
expect(impl.unload).not.called;
});

it('should now need pausing before displayed', async () => {
const ampIframe = createAmpIframe(env, {
src: iframeSrc,
Expand All @@ -1130,7 +1110,7 @@ describes.realWin(
const impl = await ampIframe.getImpl(false);
await waitForAmpIframeLayoutPromise(doc, ampIframe);
expect(ampIframe.querySelector('iframe')).to.exist;
expect(ampIframe.unlayoutOnPause()).to.be.true;
expect(ampIframe.unlayoutOnPause()).to.be.false;

// The element was never visible.
env.sandbox./*OK*/ stub(impl, 'unload');
Expand All @@ -1148,7 +1128,7 @@ describes.realWin(
});
const impl = await ampIframe.getImpl(false);
expect(ampIframe.querySelector('iframe')).to.not.exist;
expect(ampIframe.unlayoutOnPause()).to.be.true;
expect(ampIframe.unlayoutOnPause()).to.be.false;

env.sandbox./*OK*/ stub(impl, 'unload');
setDisplay(ampIframe, true);
Expand Down