Skip to content

Commit

Permalink
viewport-observer: match fix made for loading-indicator (#30883)
Browse files Browse the repository at this point in the history
* viewport-observer: match fix made for loading-indicator

* test fix
  • Loading branch information
samouri committed Oct 27, 2020
1 parent 467a57a commit b222642
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/viewport-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ export function createViewportObserver(ioCallback, win, threshold) {

// TODO(#30794): See if we can safely remove rootMargin without adversely
// affecting metrics.
const rootMargin = '25%';

// Chrome 81+ supports rootMargin in x-origin iframes via {root: document}
// but this throws in other browsers.
try {
return new win.IntersectionObserver(ioCallback, {
root,
rootMargin,
rootMargin: '25%',
threshold,
});
} catch (e) {
return new win.IntersectionObserver(ioCallback, {rootMargin, threshold});
return new win.IntersectionObserver(ioCallback, {
rootMargin: '150px',
threshold,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/test-viewport-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describes.sandboxed('Viewport Observer', {}, (env) => {
threshold: undefined,
});
expect(ctorSpy).calledWith(noop, {
rootMargin: '25%',
rootMargin: '150px',
threshold: undefined,
});
});
Expand Down

0 comments on commit b222642

Please sign in to comment.