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

🚮 Disable layers in production #23968

Closed
wants to merge 3 commits 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
1 change: 0 additions & 1 deletion build-system/global-configs/canary-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"hidden-mutation-observer": 1,
"ios-fixed-no-transfer": 1,
"ios-scrollable-iframe": 0,
"layers": 1,
"new-loaders": 1,
jridgewell marked this conversation as resolved.
Show resolved Hide resolved
"pump-early-frame": 1,
"version-locking": 1,
Expand Down
22 changes: 11 additions & 11 deletions extensions/amp-carousel/0.1/scrollable-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {BaseCarousel} from './base-carousel';
import {Layout} from '../../../src/layout';
import {Services} from '../../../src/services';
import {dev} from '../../../src/log';
import {getMode} from '../../../src/mode';
import {isExperimentOn} from '../../../src/experiments';
import {listen} from '../../../src/event-helper';
import {numeric} from '../../../src/transition';
Expand Down Expand Up @@ -47,8 +48,11 @@ export class AmpScrollableCarousel extends BaseCarousel {
/** @private {?number} */
this.scrollTimerId_ = null;

/** @private {boolean} */
this.useLayers_ = false;
/** @private @const {boolean} */
this.useLayersPrioritization_ =
getMode().localDev &&
isExperimentOn(this.win, 'layers') &&
isExperimentOn(this.win, 'layers-prioritization');
}

/** @override */
Expand All @@ -64,12 +68,8 @@ export class AmpScrollableCarousel extends BaseCarousel {
this.container_.classList.add('i-amphtml-scrollable-carousel-container');
this.element.appendChild(this.container_);

this.useLayers_ =
isExperimentOn(this.win, 'layers') &&
isExperimentOn(this.win, 'layers-prioritization');

this.cells_.forEach(cell => {
if (!this.useLayers_) {
if (!this.useLayersPrioritization_) {
Services.ownersForDoc(this.element).setOwner(cell, this.element);
}
cell.classList.add('amp-carousel-slide');
Expand All @@ -93,7 +93,7 @@ export class AmpScrollableCarousel extends BaseCarousel {
ActionTrust.LOW
);

if (this.useLayers_) {
if (this.useLayersPrioritization_) {
this.declareLayer(this.container_);
}
}
Expand All @@ -112,7 +112,7 @@ export class AmpScrollableCarousel extends BaseCarousel {

/** @override */
layoutCallback() {
if (!this.useLayers_) {
if (!this.useLayersPrioritization_) {
this.doLayout_(this.pos_);
this.preloadNext_(this.pos_, 1);
}
Expand All @@ -122,7 +122,7 @@ export class AmpScrollableCarousel extends BaseCarousel {

/** @override */
onViewportCallback(unusedInViewport) {
if (!this.useLayers_) {
if (!this.useLayersPrioritization_) {
this.updateInViewport_(this.pos_, this.pos_);
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ export class AmpScrollableCarousel extends BaseCarousel {
* @private
*/
commitSwitch_(pos) {
if (!this.useLayers_) {
if (!this.useLayersPrioritization_) {
this.updateInViewport_(pos, this.oldPos_);
this.doLayout_(pos);
this.preloadNext_(pos, Math.sign(pos - this.oldPos_));
Expand Down
12 changes: 8 additions & 4 deletions extensions/amp-image-slider/0.1/amp-image-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {Services} from '../../../src/services';
import {SwipeXRecognizer} from '../../../src/gesture-recognizers';
import {clamp} from '../../../src/utils/math';
import {dev, user, userAssert} from '../../../src/log';
import {getMode} from '../../../src/mode';
import {isExperimentOn} from '../../../src/experiments';
import {isLayoutSizeDefined} from '../../../src/layout';
import {listen} from '../../../src/event-helper';
Expand Down Expand Up @@ -103,6 +104,12 @@ export class AmpImageSlider extends AMP.BaseElement {

/** @public {boolean} */
this.isEventRegistered = false; // for test purpose

/** @private @const {boolean} */
this.useLayersPrioritization_ =
getMode().localDev &&
isExperimentOn(this.win, 'layers') &&
isExperimentOn(this.win, 'layers-prioritization');
}

/** @override */
Expand Down Expand Up @@ -145,10 +152,7 @@ export class AmpImageSlider extends AMP.BaseElement {
);

// TODO(kqian): remove this after layer launch
if (
!isExperimentOn(this.win, 'layers') ||
!isExperimentOn(this.win, 'layers-prioritization')
) {
if (!this.useLayersPrioritization_) {
// see comment in layoutCallback
// When layers not enabled
const owners = Services.ownersForDoc(this.element);
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-live-list/0.1/amp-live-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {AmpEvents} from '../../../src/amp-events';
import {CSS} from '../../../build/amp-live-list-0.1.css';
import {Layout} from '../../../src/layout';
import {childElementByAttr} from '../../../src/dom';
import {getMode} from '../../../src/mode';
import {isExperimentOn} from '../../../src/experiments';
import {user, userAssert} from '../../../src/log';

Expand Down Expand Up @@ -998,7 +999,7 @@ export class AmpLiveList extends AMP.BaseElement {
* @return {boolean}
*/
isElementBelowViewport_(element) {
if (isExperimentOn(this.win, 'layers')) {
if (getMode().localDev && isExperimentOn(this.win, 'layers')) {
// Well, if the scroller is above the viewport, but the element is way
// down in the box, is it above or below?
return this.viewport_.getLayoutRect(element).top > 0;
Expand Down
2 changes: 1 addition & 1 deletion src/base-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ export class BaseElement {
*/
declareLayer(opt_element) {
devAssert(
isExperimentOn(this.win, 'layers'),
getMode().localDev && isExperimentOn(this.win, 'layers'),
'Layers must be enabled to declare layer.'
);
if (opt_element) {
Expand Down
4 changes: 2 additions & 2 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function createBaseCustomElementClass(win) {
// Resources can now be initialized since the ampdoc is now available.
this.resources_ = Services.resourcesForDoc(this.ampdoc_);
}
if (isExperimentOn(this.ampdoc_.win, 'layers')) {
if (getMode().localDev && isExperimentOn(this.ampdoc_.win, 'layers')) {
if (!this.layers_) {
// Resources can now be initialized since the ampdoc is now available.
this.layers_ = Services.layersForDoc(this.ampdoc_);
Expand Down Expand Up @@ -1000,7 +1000,7 @@ function createBaseCustomElementClass(win) {

this.isConnected_ = false;
this.getResources().remove(this);
if (isExperimentOn(this.ampdoc_.win, 'layers')) {
if (getMode().localDev && isExperimentOn(this.ampdoc_.win, 'layers')) {
this.getLayers().remove(this);
}
this.implementation_.detachedCallback();
Expand Down
3 changes: 2 additions & 1 deletion src/inabox/inabox-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {ViewportBindingDef} from '../service/viewport/viewport-binding-def';
import {ViewportImpl} from '../service/viewport/viewport-impl';
import {canInspectWindow} from '../iframe-helper';
import {dev, devAssert} from '../log';
import {getMode} from '../mode';
import {getPositionObserver} from '../../ads/inabox/position-observer';
import {iframeMessagingClientFor} from './inabox-iframe-messaging-client';
import {isExperimentOn} from '../experiments';
Expand Down Expand Up @@ -152,7 +153,7 @@ export class ViewportBindingInabox {
);

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(this.win, 'layers');

/** @private {?../../ads/inabox/position-observer.PositionObserver} */
this.topWindowPositionObserver_ = null;
Expand Down
14 changes: 7 additions & 7 deletions src/service/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Layout} from '../layout';
import {Services} from '../services';
import {computedStyle, toggle} from '../style';
import {dev, devAssert} from '../log';
import {getMode} from '../mode';
import {isBlockedByConsent} from '../error';
import {isExperimentOn} from '../experiments';
import {
Expand Down Expand Up @@ -214,13 +215,12 @@ export class Resource {
this.loadPromiseResolve_ = deferred.resolve;

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.hostWin, 'layers');
this.useLayers_ =
getMode().localDev && isExperimentOn(this.hostWin, 'layers');

/** @private @const {boolean} */
this.useLayersPrioritization_ = isExperimentOn(
this.hostWin,
'layers-prioritization'
);
this.useLayersPrioritization_ =
this.useLayers_ && isExperimentOn(this.hostWin, 'layers-prioritization');
}

/**
Expand Down Expand Up @@ -749,7 +749,7 @@ export class Resource {

/** @return {!ViewportRatioDef} */
getDistanceViewportRatio() {
if (this.useLayers_ && this.useLayersPrioritization_) {
if (this.useLayersPrioritization_) {
const {element} = this;
return {
distance: element
Expand Down Expand Up @@ -811,7 +811,7 @@ export class Resource {
}
const {distance, scrollPenalty, viewportHeight} =
opt_viewportRatio || this.getDistanceViewportRatio();
if (this.useLayers_ && this.useLayersPrioritization_) {
if (this.useLayersPrioritization_) {
return dev().assertNumber(distance) < multiplier;
}
if (typeof distance == 'boolean') {
Expand Down
11 changes: 5 additions & 6 deletions src/service/resources-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {closest, hasNextNodeInDocumentOrder} from '../dom';
import {computedStyle} from '../style';
import {dev, devAssert, user} from '../log';
import {dict, hasOwn} from '../utils/object';
import {getMode} from '../mode';
import {getSourceUrl, isProxyOrigin} from '../url';
import {checkAndFix as ieMediaCheckAndFix} from './ie-media-bug';
import {isArray} from '../types';
Expand Down Expand Up @@ -402,16 +403,14 @@ export class Resources {
this.queue_ = new TaskQueue();

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(this.win, 'layers');

/** @private @const {boolean} */
this.useLayersPrioritization_ = isExperimentOn(
this.win,
'layers-prioritization'
);
this.useLayersPrioritization_ =
this.useLayers_ && isExperimentOn(this.win, 'layers-prioritization');

let boundScorer;
if (this.useLayers_ && this.useLayersPrioritization_) {
if (this.useLayersPrioritization_) {
boundScorer = this.calcTaskScoreLayers_.bind(this);
} else {
boundScorer = this.calcTaskScore_.bind(this);
Expand Down
3 changes: 2 additions & 1 deletion src/service/viewport/viewport-binding-ios-embed-sd.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
setInitialDisplay,
} from '../../style';
import {dev} from '../../log';
import {getMode} from '../../mode';
import {htmlFor} from '../../static-template';
import {isExperimentOn} from '../../experiments';
import {layoutRectLtwh} from '../../layout-rect';
Expand Down Expand Up @@ -170,7 +171,7 @@ export class ViewportBindingIosEmbedShadowRoot_ {
this.boundResizeEventListener_ = this.onResized_.bind(this);

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(this.win, 'layers');

/** @private {boolean} */
this.bodySyncScheduled_ = false;
Expand Down
3 changes: 2 additions & 1 deletion src/service/viewport/viewport-binding-ios-embed-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from './viewport-binding-def';
import {computedStyle, px, setImportantStyles} from '../../style';
import {dev} from '../../log';
import {getMode} from '../../mode';
import {isExperimentOn} from '../../experiments';
import {layoutRectLtwh} from '../../layout-rect';
import {waitForBodyOpen} from '../../dom';
Expand Down Expand Up @@ -74,7 +75,7 @@ export class ViewportBindingIosEmbedWrapper_ {
this.boundResizeEventListener_ = () => this.resizeObservable_.fire();

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(this.win, 'layers');

/** @private {number} */
this.paddingTop_ = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/service/viewport/viewport-binding-natural.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from './viewport-binding-def';
import {computedStyle, px, setImportantStyles} from '../../style';
import {dev} from '../../log';
import {getMode} from '../../mode';
import {isExperimentOn} from '../../experiments';
import {layoutRectLtwh} from '../../layout-rect';

Expand Down Expand Up @@ -67,7 +68,7 @@ export class ViewportBindingNatural_ {
this.boundResizeEventListener_ = () => this.resizeObservable_.fire();

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(this.win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(this.win, 'layers');

dev().fine(TAG_, 'initialized natural viewport');
}
Expand Down
2 changes: 1 addition & 1 deletion src/service/viewport/viewport-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class ViewportImpl {
this.originalViewportMetaString_ = undefined;

/** @private @const {boolean} */
this.useLayers_ = isExperimentOn(win, 'layers');
this.useLayers_ = getMode().localDev && isExperimentOn(win, 'layers');
if (this.useLayers_) {
installLayersServiceForDoc(
ampdoc,
Expand Down