Skip to content

Commit

Permalink
Ignore V1 elements in the inabox resource manager (#32948)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Voytenko committed Feb 27, 2021
1 parent 6b07125 commit 1a6b196
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/inabox/inabox-resources.js
Expand Up @@ -214,14 +214,15 @@ export class InaboxResources {
dev().fine(TAG, 'doPass');
// measure in a batch
this.resources_.forEach((resource) => {
if (!resource.isLayoutPending()) {
if (!resource.isLayoutPending() || resource.element.V1()) {
return;
}
resource.measure();
});
// mutation in a batch
this.resources_.forEach((resource) => {
if (
!resource.element.V1() &&
resource.getState() === ResourceState.READY_FOR_LAYOUT &&
resource.isDisplayed()
) {
Expand Down
41 changes: 41 additions & 0 deletions test/unit/inabox/test-inabox-resources.js
Expand Up @@ -15,6 +15,7 @@
*/
import {Deferred} from '../../../src/utils/promise';
import {InaboxResources} from '../../../src/inabox/inabox-resources';
import {ResourceState} from '../../../src/service/resource';
import {macroTask} from '../../../testing/yield';
import {toggleExperiment} from '../../../src/experiments';

Expand Down Expand Up @@ -147,4 +148,44 @@ describes.realWin('inabox-resources', {amp: true}, (env) => {
expect(resource1.unload).to.be.calledOnce;
expect(resource2.unload).to.be.calledOnce;
});

it('should ignore V1 resources for layout pass', async () => {
const element1 = env.createAmpElement('amp-foo');
const element2 = env.createAmpElement('amp-bar');
env.sandbox.stub(element2, 'V1').returns(true);

win.document.body.appendChild(element1);
win.document.body.appendChild(element2);
resources.add(element1);
resources.add(element2);

const resource1 = resources.get()[0];
const resource2 = resources.get()[1];
env.sandbox.stub(resource1, 'measure');
env.sandbox.stub(resource2, 'measure');
env.sandbox.stub(resource1, 'startLayout');
env.sandbox.stub(resource2, 'startLayout');

env.sandbox.stub(resource1, 'build').resolves();
env.sandbox.stub(resource2, 'build').resolves();
env.sandbox
.stub(resource1, 'getState')
.returns(ResourceState.READY_FOR_LAYOUT);
env.sandbox
.stub(resource2, 'getState')
.returns(ResourceState.READY_FOR_LAYOUT);
env.sandbox.stub(resource1, 'isDisplayed').returns(true);
env.sandbox.stub(resource2, 'isDisplayed').returns(true);
resources.upgraded(element1);

resources.schedulePass(0);
await new Promise(setTimeout);
await new Promise(setTimeout);

expect(resource1.measure).to.be.called;
expect(resource2.measure).to.not.be.called;

expect(resource1.startLayout).to.be.called;
expect(resource2.startLayout).to.not.be.called;
});
});

0 comments on commit 1a6b196

Please sign in to comment.