diff --git a/src/service/layers-impl.js b/src/service/layers-impl.js index 5620ea7756742..9b6d6d3243bac 100644 --- a/src/service/layers-impl.js +++ b/src/service/layers-impl.js @@ -721,10 +721,10 @@ export class LayoutElement { dev().assert(this.isLayer()); dev().assert(this.contains(child)); - // Parents track the children, but not all children are aware of there + // Parents track the children, but not all children are aware of their // parents. When a child finds its parent, it adds itself to the parent. // This might lead to a double tracking. - if (this.children_.indexOf(child) === -1) { + if (!this.children_.includes(child)) { this.children_.push(child); } } diff --git a/test/functional/test-layers.js b/test/functional/test-layers.js index fa97abcf34537..ce786bf9d5b43 100644 --- a/test/functional/test-layers.js +++ b/test/functional/test-layers.js @@ -131,6 +131,26 @@ describes.realWin('Layers', {amp: true}, env => { expect(layer).to.equal(LayoutElement.for(parent)); }); + it('does not cause double references in layer tree', () => { + const layers = Services.layersForDoc(root); + const div = createElement(); + root.appendChild(div); + layers.add(div); + + const layout = LayoutElement.for(div); + const rootLayout = LayoutElement.for(scrollingElement); + expect(layout.getParentLayer()).to.equal(rootLayout); + + layout.forgetParentLayer(); + expect(layout.getParentLayer()).to.equal(rootLayout); + + const spy = sinon.sandbox.spy(div, 'getBoundingClientRect'); + rootLayout.dirtyMeasurements(); + rootLayout.remeasure(); + + expect(spy).to.have.callCount(1); + }); + describe('inside FIE', () => { let iframe; let iframeBody;