Skip to content

Commit

Permalink
🚀 [Story performance] Disable animations on first page if story is tr…
Browse files Browse the repository at this point in the history
…ansformed (#37135)

* Add isTransformed

* Added isTransformed to report

* Added stories transformed

* Removed story-

* Added inline css CSI

* Added comment

* Updated comment
  • Loading branch information
mszylkowski committed Dec 7, 2021
1 parent 37c8e7c commit 788b14d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
16 changes: 15 additions & 1 deletion extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -417,12 +418,25 @@ 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'
);
}
// [i-amphtml-version] marks that the style was inlined in the doc server-side.
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(
'story-load-inactive-outside-viewport'
Expand Down
5 changes: 3 additions & 2 deletions extensions/amp-story/1.0/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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_ =
Expand Down
9 changes: 9 additions & 0 deletions extensions/amp-story/1.0/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

0 comments on commit 788b14d

Please sign in to comment.