Skip to content

Commit

Permalink
Use current visibility state of canvas. Fixes #310
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sevaseva authored and brianzinn committed Feb 21, 2024
1 parent 67fa509 commit 9847c4b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/react-babylonjs/src/Engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 9847c4b

Please sign in to comment.