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

Workspace: deferred build mode #32002

Closed
wants to merge 1 commit into from
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
2 changes: 1 addition & 1 deletion builtins/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ATTRIBUTES_TO_PROPAGATE = [
export class AmpImg extends BaseElement {
/** @override @nocollapse */
static V1() {
return V1_IMG_DEFERRED_BUILD;
return true;
}

/** @override @nocollapse */
Expand Down
94 changes: 94 additions & 0 deletions examples/loader-bento.amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lorem Ipsum | PublisherName</title>
<link rel="canonical" href="https://medium.com/p/cb7f223fad86" >
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script>
(self.AMP = self.AMP || []).push(function(AMP) {
AMP.toggleExperiment('bento', true, true);
});
</script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-1.0.js"></script>
<script async custom-element="amp-instagram" src="https://cdn.ampproject.org/v0/amp-instagram-1.0.js"></script>

<style amp-custom>
body {
margin: 0;
font-family: 'Georgia', Serif;
background: white;
}

</style>
<link href='https://fonts.googleapis.com/css?family=Georgia|Open+Sans|Roboto' rel='stylesheet' type='text/css'>
</head>
<body>
<!--
<div style="height: 500vh">scroll</div>
-->

<!--
-->
<amp-img id="hero-img"
src="img/[email protected]"
srcset="img/[email protected] 1x, img/[email protected] 2x"
layout="responsive" width="360"
height="216"
noprerender>
<script>
//debugger;//QQQQQQ
</script>
</amp-img>

<!--
<amp-video id="video1"
src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
width="358"
height="204"
layout="responsive"
controls>
<script>
//debugger;//QQQQQQ
</script>
</amp-video>
-->

<!--
<amp-iframe id="iframe1"
width=300 height=300
sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
layout="responsive"
frameborder="0"
src="http://ads.localhost:8000/extensions/amp-iframe/0.1/storybook/iframe.html">
<div placeholder></div>
</amp-iframe>
-->

<!--
<amp-carousel id="carousel1" width=400 height=300 layout=fixed type=slides>
<amp-img id="hero-img"
src="img/[email protected]"
srcset="img/[email protected] 1x, img/[email protected] 2x"
layout="responsive" width="360"
height="216">
</amp-img>
<amp-video id="video1"
src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
width="358"
height="204"
layout="responsive"
controls></amp-video>
<amp-instagram id="insta1"
width=300 height=300
layout="responsive"
data-shortcode="B8QaZW4AQY_">
</amp-instagram>
</amp-carousel>
-->

<div style="height: 2000vh">scroll</div>
</body>
</html>
97 changes: 97 additions & 0 deletions examples/loader.amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>Lorem Ipsum | PublisherName</title>
<link rel="canonical" href="https://medium.com/p/cb7f223fad86" >
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-video" src="https://cdn.ampproject.org/v0/amp-video-0.1.js"></script>
<script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>

<style amp-custom>
body {
margin: 0;
font-family: 'Georgia', Serif;
background: white;
}

</style>
<link href='https://fonts.googleapis.com/css?family=Georgia|Open+Sans|Roboto' rel='stylesheet' type='text/css'>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>
<!--
<div style="height: 500vh">scroll</div>
-->

<!--
-->
<amp-img id="hero-img"
src="img/[email protected]"
srcset="img/[email protected] 1x, img/[email protected] 2x"
layout="responsive" width="360"
height="216"
noprerender_>
<script>
//debugger;//QQQQQQ
</script>
</amp-img>

<!--
<amp-video id="video1"
src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
width="358"
height="204"
layout="responsive"
controls>
<script>
//debugger;//QQQQQQ
</script>
</amp-video>
-->

<!--
<amp-iframe id="iframe1"
width=300 height=100
sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
layout="responsive"
frameborder="0"
src="http://ads.localhost:8000/extensions/amp-iframe/0.1/storybook/iframe.html"
resizable>
<div placeholder></div>
<div overflow>overflow</div>
</amp-iframe>
-->

<!--
<amp-carousel id="carousel1" width=400 height=300 layout=fixed type=slides>
<amp-img id="hero-img"
src="img/[email protected]"
srcset="img/[email protected] 1x, img/[email protected] 2x"
layout="responsive" width="360"
height="216">
</amp-img>
<amp-video id="video1"
src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4"
width="358"
height="204"
layout="responsive"
controls></amp-video>
<amp-iframe id="iframe1"
width=300 height=300
sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"
layout="responsive"
frameborder="0"
src="http://ads.localhost:8000/extensions/amp-iframe/0.1/storybook/iframe.html">
<div placeholder></div>
</amp-iframe>
</amp-carousel>
-->

<!--
-->
<div style="height: 2000vh">scroll</div>
</body>
</html>
88 changes: 87 additions & 1 deletion extensions/amp-iframe/0.1/amp-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ let count = 0;
let trackingIframeTimeout = 5000;

export class AmpIframe extends AMP.BaseElement {
/** @override @nocollapse */
static V1() {
return true;
}

/** @param {!AmpElement} element */
constructor(element) {
super(element);
Expand Down Expand Up @@ -305,6 +310,30 @@ export class AmpIframe extends AMP.BaseElement {
this.container_ = makeIOsScrollable(this.element);

this.registerIframeMessaging_();

if (AmpIframe.V1()) {
this.layoutCallback();
}
}

/** @override */
ensureLoaded() {
if (!this.iframe_) {
this.layoutCallback();
}
}

/** @override */
attachedCallback() {
observeDisplay(this.element, this.onDisplay_);
if (AmpIframe.V1()) {
this.setReadyState('loading');
}
}

/** @override */
detachedCallback() {
unobserveDisplay(this.element, this.onDisplay_);
}

/** @override */
Expand Down Expand Up @@ -405,6 +434,19 @@ export class AmpIframe extends AMP.BaseElement {

const iframe = this.element.ownerDocument.createElement('iframe');

if (AmpIframe.V1()) {
this.setReadyState('loading');
if (iframe.readyState == 'complete') {
this.setReadyState('complete');
}
listen(iframe, 'load', () => {
this.setReadyState('complete');
});
listen(iframe, 'error', (reason) => {
this.setReadyState('error', reason);
});
}

this.iframe_ = /** @type {HTMLIFrameElement} */ (iframe);

this.applyFillContent(iframe);
Expand Down Expand Up @@ -482,6 +524,12 @@ export class AmpIframe extends AMP.BaseElement {

this.container_.appendChild(iframe);

// DO NOT SUBMIT: might be worth to just fork amp-iframe completely for V2.
if (!AmpIframe.V1()) {
this.isDisplayed_ = false;
observeDisplay(this.element, this.onDisplay_);
}

return this.loadPromise(iframe).then(() => {
// On iOS the iframe at times fails to render inside the `overflow:auto`
// container. To avoid this problem, we set the `overflow:auto` property
Expand Down Expand Up @@ -572,6 +620,9 @@ export class AmpIframe extends AMP.BaseElement {
* @override
**/
unlayoutCallback() {
if (!AmpIframe.V1()) {
unobserveDisplay(this.element, this.onDisplay_);
}
if (this.unlistenPym_) {
this.unlistenPym_();
this.unlistenPym_ = null;
Expand Down Expand Up @@ -628,6 +679,38 @@ export class AmpIframe extends AMP.BaseElement {
return true;
}

/**
* @param {boolean} isDisplayed
* @private
*/
onDisplay_(isDisplayed) {
console.log(
'amp-iframe: onDisplay_:',
isDisplayed,
this.isDisplayed_,
!!this.iframe_
);
if (isDisplayed === this.isDisplayed_) {
return;
}
this.isDisplayed_ = isDisplayed;

if (AmpIframe.V1()) {
const iframeExists = !!this.iframe_;
if (isDisplayed !== iframeExists) {
if (isDisplayed) {
this.layoutCallback();
} else {
this.unlayoutCallback();
}
}
} else {
if (!isDisplayed && this.iframe_) {
this.getVsync().mutate(() => this.unload());
}
}
}

/**
* Makes the iframe visible.
* @private
Expand Down Expand Up @@ -718,6 +801,7 @@ export class AmpIframe extends AMP.BaseElement {
if (newHeight !== undefined || newWidth !== undefined) {
this.attemptChangeSize(newHeight, newWidth).then(
() => {
console.log('amp-iframe: updateSize_: approved');
if (newHeight !== undefined) {
this.element.setAttribute('height', newHeight);
}
Expand All @@ -730,7 +814,9 @@ export class AmpIframe extends AMP.BaseElement {
newWidth
);
},
() => {}
() => {
console.log('amp-iframe: updateSize_: denied');
}
);
} else {
this.user().error(
Expand Down
33 changes: 33 additions & 0 deletions extensions/amp-video/0.1/amp-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ const ATTRS_TO_PROPAGATE = ATTRS_TO_PROPAGATE_ON_BUILD.concat(
* @implements {../../../src/video-interface.VideoInterface}
*/
export class AmpVideo extends AMP.BaseElement {
/** @override @nocollapse */
static V1() {
return true;
}

/**
* AMP Cache may selectively cache certain video sources (based on various
* heuristics such as video type, extensions, etc...).
Expand Down Expand Up @@ -264,6 +269,30 @@ export class AmpVideo extends AMP.BaseElement {
installVideoManagerForDoc(element);

Services.videoManagerForDoc(element).register(this);

if (AmpVideo.V1()) {
this.setReadyState('loading');

const video = devAssert(this.video_);

if (video.readyState > 0) {
this.setReadyState('complete');
}
listen(video, 'loadedmetadata', () => {
this.setReadyState('complete');
});
listen(video, 'error', (reason) => {
this.setReadyState('error', reason);
});

this.layoutCallback();
}
}

/** @override */
ensureLoaded() {
const video = dev().assertElement(this.video_);
video.loading = 'eager';
}

/**
Expand Down Expand Up @@ -339,6 +368,10 @@ export class AmpVideo extends AMP.BaseElement {
// TODO(@aghassemi, 10756) Either make metadata observable or submit
// an event indicating metadata changed (in case metadata changes
// while the video is playing).

if (AmpVideo.V1() && this.video_.readyState === 0) {
this.setReadyState('loading');
}
}

/** @override */
Expand Down
Loading