react-intersection-observer icon indicating copy to clipboard operation
react-intersection-observer copied to clipboard

inView remains false on Chrome on Samsung Galaxy Tab 7 if `threshold: 1` is used

Open amarcher opened this issue 4 years ago • 7 comments

Description

Specifically when using Chrome on a Samsung Galaxy Tab 7 and setting threshold to 1, the useInView hook returns a value of inView that never changes to true when the element is fully scrolled into the viewport. Interestingly enough a value of 0.9 works just fine.

Steps to Reproduce

  1. Use an useInView hook and provide { threshold: 1 } as an argument.
  2. Using Chrome on a Samsung Galaxy Tab 7, scroll the element fully into the viewport

Expected Behavior

The inView value returned from the hook should be true

Observed Behavior

The inView value returned from the hook remains false

Screenshots

Screen Shot 2021-11-01 at 3 54 00 PM

Tablet

  • Device: Samsung Galaxy Tab 7
  • OS: Android
  • Browser Chrome
  • Version 95.0.4638.50

Additional Context

Interestingly enough a value of 0.9 works just fine.

Screen Shot 2021-11-01 at 3 58 36 PM

amarcher avatar Nov 01 '21 20:11 amarcher

Interesting. Question is if it's a problem with the Intersection Observer API itself, in that specific browser.

thebuilder avatar Nov 02 '21 07:11 thebuilder

I just verified that Intersection Observer API itself works with threshold: 1 in that specific browser by loading this forked codepen example in the Samsung Galaxy Tab 7 Chrome browser via Browserstack.

Screen Shot 2021-11-02 at 10 42 59 AM

amarcher avatar Nov 02 '21 14:11 amarcher

Do you have time to debug this further?

  • Is the observer correctly triggered? https://github.com/thebuilder/react-intersection-observer/blob/master/src/observe.ts#L58
  • Is entry.isIntersecting set to true when intersecting?
  • Is it something silly like the JS not doing the math correctly? So the entry.intersectionRatio >= threshold is evaluated as 1 >= 1 // false?

thebuilder avatar Nov 03 '21 09:11 thebuilder

I attempted to debug by creating a local copy of the observe function in the fork and using a Samsung Galaxy Tab 7 via Browserstack to view the console output.

When options with threshold: 1 are provided, we see console output on mount as the observer is initialized, but no calls to the unobserve function, and no further console output when the observed element is scrolled into view. 🤔

Something that's worth noting is that a DOM exception seems to be thrown a few seconds after the page loads:

Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Data cannot be cloned, out of memory.
    at S (https://codesandbox.io/typescript-worker.d04a8b00.worker.js:1:796824)
    at https://codesandbox.io/typescript-worker.d04a8b00.worker.js:1:797128

amarcher avatar Nov 03 '21 19:11 amarcher

I also tried using the IntersectionObserver API directly (with the forked codepen example from above) and checking that properties like intersectionRatio, isIntersecting, and isVisible exist on the entry when a threshold: 1 is used in that browser (they do, and are 1, true, and true respectively). 🤔

amarcher avatar Nov 03 '21 19:11 amarcher

I attempted to debug by creating a local copy of the observe function in the fork and using a Samsung Galaxy Tab 7 via Browserstack to view the console output.

When options with threshold: 1 are provided, we see console output on mount as the observer is initialized, but no calls to the unobserve function, and no further console output when the observed element is scrolled into view. 🤔

Something that's worth noting is that a DOM exception seems to be thrown a few seconds after the page loads:

Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Data cannot be cloned, out of memory.
    at S (https://codesandbox.io/typescript-worker.d04a8b00.worker.js:1:796824)
    at https://codesandbox.io/typescript-worker.d04a8b00.worker.js:1:797128

This is really weird. It triggers the intersection observer when you resize the window, but not when scrolling. Since it's using the IntersectionObserver more or less directly, and it doesn't trigger the callback, it seems like it's a bug with the API itself?

thebuilder avatar Nov 04 '21 08:11 thebuilder

Is this still an issue?

thebuilder avatar Jun 21 '22 22:06 thebuilder