From 9847c4bc7a58f2d20fcc8f2d499f5d06234bdb00 Mon Sep 17 00:00:00 2001 From: Seva Lotoshnikov Date: Tue, 20 Feb 2024 20:45:18 -0600 Subject: [PATCH] Use current visibility state of canvas. Fixes #310 Even though the observer is created with one `threshold`, it may be notified with multiple successive entries (with different `entry.time` values) at once (perhaps if multiple DOM modification were made in the main thread and intermediate notification could not have been sent). While I am here, removing logging that's confusing to devs, end users. --- packages/react-babylonjs/src/Engine.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-babylonjs/src/Engine.tsx b/packages/react-babylonjs/src/Engine.tsx index 1744cba1..6b82d818 100644 --- a/packages/react-babylonjs/src/Engine.tsx +++ b/packages/react-babylonjs/src/Engine.tsx @@ -30,9 +30,9 @@ const useCanvasObserver = ( } const callbackFn: IntersectionObserverCallback = (entries) => { - const [entry] = entries - shouldRenderRef.current = entry.isIntersecting - console.log('should render updating:', shouldRenderRef.current) + // Last entry represents the latest, current state. + const lastEntry = entries[entries.length - 1] + shouldRenderRef.current = lastEntry.isIntersecting } const observer = new IntersectionObserver(callbackFn, { threshold })