Skip to content

Commit

Permalink
fix: ensure thresholds is defined (#415)
Browse files Browse the repository at this point in the history
Sometimes the thresholds value on the IntersectionObserver instance could be undefined. Add a fallback to a default value in the cases where the browser doesn't set it.

This fixes #414
  • Loading branch information
thebuilder authored Nov 11, 2020
1 parent 9312d1d commit 76405d7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/observers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function createObserver(options: IntersectionObserverInit) {
// -Firefox ignores `threshold` when considering `isIntersecting`, so it will never be false again if `threshold` is > 0
const inView =
entry.isIntersecting &&
observer.thresholds.some(
(observer.thresholds ?? [0]).some(
(threshold) => entry.intersectionRatio >= threshold,
);

Expand Down

1 comment on commit 76405d7

@vercel
Copy link

@vercel vercel bot commented on 76405d7 Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.