From 2af45fb1ee95dc29e7d8c04b5f0081a6fdd45d66 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 12:59:24 -0500 Subject: [PATCH 1/7] Add isTransformed --- extensions/amp-story/1.0/animation.js | 5 +++-- extensions/amp-story/1.0/utils.js | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/extensions/amp-story/1.0/animation.js b/extensions/amp-story/1.0/animation.js index 25386a4ef599..fcf960ac0eae 100644 --- a/extensions/amp-story/1.0/animation.js +++ b/extensions/amp-story/1.0/animation.js @@ -27,7 +27,7 @@ import { scopedQuerySelector, scopedQuerySelectorAll, } from '#core/dom/query'; -import {timeStrToMillis, unscaledClientRect} from './utils'; +import {isTransformed, timeStrToMillis, unscaledClientRect} from './utils'; import {isExperimentOn} from '#experiments'; import {isPreviewMode} from './embed-mode'; @@ -548,7 +548,8 @@ export class AnimationManager { const firstPageAnimationDisabled = isExperimentOn(ampdoc.win, 'story-disable-animations-first-page') || - isPreviewMode(ampdoc.win); + isPreviewMode(ampdoc.win) || + isTransformed(ampdoc); /** @private @const {bool} */ this.skipAnimations_ = diff --git a/extensions/amp-story/1.0/utils.js b/extensions/amp-story/1.0/utils.js index 20182ff05f5c..2d639c48ccb4 100644 --- a/extensions/amp-story/1.0/utils.js +++ b/extensions/amp-story/1.0/utils.js @@ -333,3 +333,12 @@ export const maybeMakeProxyUrl = (url, ampDoc) => { ); return loc.origin + '/i/s/' + resolvedRelativeUrl.replace(/https?:\/\//, ''); }; + +/** + * Whether the document is transformed + * @param {!AmpDoc} ampdoc + * @return {boolean} + */ +export function isTransformed(ampdoc) { + return ampdoc.getRootNode().documentElement.hasAttribute('transformed'); +} From a2352bbcf09e2d23549924102d2ca7bf841645da Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 13:17:24 -0500 Subject: [PATCH 2/7] Added isTransformed to report --- extensions/amp-story/1.0/amp-story.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 95d855a089f5..db36354da303 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -92,6 +92,7 @@ import {isPreviewMode} from './embed-mode'; import {isRTL, removeElement} from '#core/dom'; import {parseQueryString} from '#core/types/string/url'; import { + isTransformed, removeAttributeInMutate, setAttributeInMutate, shouldShowStoryUrlInfo, @@ -417,7 +418,8 @@ export class AmpStory extends AMP.BaseElement { if ( isExperimentOn(this.win, 'story-disable-animations-first-page') || isPreviewMode(this.win) || - prefersReducedMotion(this.win) + prefersReducedMotion(this.win) || + isTransformed(this.getAmpDoc()) ) { Services.performanceFor(this.win).addEnabledExperiment( 'story-disable-animations-first-page' From f4fda28ae2639a703374b58a698f453bc7a565f9 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 13:31:19 -0500 Subject: [PATCH 3/7] Added stories transformed --- extensions/amp-story/1.0/amp-story.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index db36354da303..94633e4f7fea 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -92,6 +92,7 @@ import {isPreviewMode} from './embed-mode'; import {isRTL, removeElement} from '#core/dom'; import {parseQueryString} from '#core/types/string/url'; import { + isTransformed, isTransformed, removeAttributeInMutate, setAttributeInMutate, @@ -415,16 +416,20 @@ export class AmpStory extends AMP.BaseElement { 'story-load-first-page-only' ); } + const isStoryTransformed = isTransformed(this.getAmpDoc()); if ( isExperimentOn(this.win, 'story-disable-animations-first-page') || isPreviewMode(this.win) || prefersReducedMotion(this.win) || - isTransformed(this.getAmpDoc()) + isStoryTransformed ) { Services.performanceFor(this.win).addEnabledExperiment( 'story-disable-animations-first-page' ); } + if (isStoryTransformed) { + Services.performanceFor(this.win).addEnabledExperiment('story-transformed'); + } if (isExperimentOn(this.win, 'story-load-inactive-outside-viewport')) { Services.performanceFor(this.win).addEnabledExperiment( 'story-load-inactive-outside-viewport' From f5c45f3b3a1518092088d86f5cb9033a2498d8fd Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 13:32:21 -0500 Subject: [PATCH 4/7] Removed story- --- extensions/amp-story/1.0/amp-story.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 94633e4f7fea..519084838570 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -428,7 +428,7 @@ export class AmpStory extends AMP.BaseElement { ); } if (isStoryTransformed) { - Services.performanceFor(this.win).addEnabledExperiment('story-transformed'); + Services.performanceFor(this.win).addEnabledExperiment('transformed'); } if (isExperimentOn(this.win, 'story-load-inactive-outside-viewport')) { Services.performanceFor(this.win).addEnabledExperiment( From 1be10afd7079e2ec699861920c8863bf0b17fb76 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 14:09:46 -0500 Subject: [PATCH 5/7] Added inline css CSI --- extensions/amp-story/1.0/amp-story.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 519084838570..8e0846dd95a3 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -92,7 +92,6 @@ import {isPreviewMode} from './embed-mode'; import {isRTL, removeElement} from '#core/dom'; import {parseQueryString} from '#core/types/string/url'; import { - isTransformed, isTransformed, removeAttributeInMutate, setAttributeInMutate, @@ -416,19 +415,26 @@ export class AmpStory extends AMP.BaseElement { 'story-load-first-page-only' ); } - const isStoryTransformed = isTransformed(this.getAmpDoc()); if ( isExperimentOn(this.win, 'story-disable-animations-first-page') || isPreviewMode(this.win) || prefersReducedMotion(this.win) || - isStoryTransformed + isTransformed(this.getAmpDoc()) ) { Services.performanceFor(this.win).addEnabledExperiment( 'story-disable-animations-first-page' ); } - if (isStoryTransformed) { - Services.performanceFor(this.win).addEnabledExperiment('transformed'); + if ( + this.getAmpDoc() + .getRootNode() + .documentElement.querySelector( + 'style[amp-extension="amp-story"][i-amphtml-version]' + ) + ) { + Services.performanceFor(this.win).addEnabledExperiment( + 'story-inline-css' + ); } if (isExperimentOn(this.win, 'story-load-inactive-outside-viewport')) { Services.performanceFor(this.win).addEnabledExperiment( From 2037bee5a35e3feb6a13014116f5f9cfd365a5a9 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 14:35:43 -0500 Subject: [PATCH 6/7] Added comment --- extensions/amp-story/1.0/amp-story.js | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 8e0846dd95a3..935bc603721d 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -432,6 +432,7 @@ export class AmpStory extends AMP.BaseElement { 'style[amp-extension="amp-story"][i-amphtml-version]' ) ) { + // Reports that a transformer inlined the amp-story CSS. Services.performanceFor(this.win).addEnabledExperiment( 'story-inline-css' ); From 19339002a2c24b3d1e388111a655bafbc30e5c85 Mon Sep 17 00:00:00 2001 From: Matias Szylkowski Date: Tue, 7 Dec 2021 14:40:29 -0500 Subject: [PATCH 7/7] Updated comment --- extensions/amp-story/1.0/amp-story.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/amp-story/1.0/amp-story.js b/extensions/amp-story/1.0/amp-story.js index 935bc603721d..4eb15dabd855 100644 --- a/extensions/amp-story/1.0/amp-story.js +++ b/extensions/amp-story/1.0/amp-story.js @@ -425,6 +425,7 @@ export class AmpStory extends AMP.BaseElement { 'story-disable-animations-first-page' ); } + // [i-amphtml-version] marks that the style was inlined in the doc server-side. if ( this.getAmpDoc() .getRootNode() @@ -432,7 +433,6 @@ export class AmpStory extends AMP.BaseElement { 'style[amp-extension="amp-story"][i-amphtml-version]' ) ) { - // Reports that a transformer inlined the amp-story CSS. Services.performanceFor(this.win).addEnabledExperiment( 'story-inline-css' );