Resets a callback whenever the browser tab is hidden or the window loses focus, guarding against `pointerleave`/`pointercancel` events being swallowed during tab switches or overlay interruptions. ## Key Components - **`useResetOnPageHidden(reset)`** — React hook that attaches `blur` (on `window`) and `visibilitychange` (on `document`) listeners; invokes `reset` when either fires (visibility only on `'hidden'`). Cleans up both listeners on unmount or when `reset` identity changes. ## Usage Example ```typescript import { useCallback, useState } from 'react' import { useResetOnPageHidden } from './use-reset-on-page-hidden' function MarqueeWall() { const [isHovered, setIsHovered] = useState(false) // Must be stable — memoize with useCallback to avoid re-attaching listeners const resetHover = useCallback(() => setIsHovered(false), []) useResetOnPageHidden(resetHover) return (
setIsHovered(true)} onPointerLeave={() => setIsHovered(false)} > {/* marquee pauses when isHovered is true */}
) } ``` ## Notes - Pass a **stable** `reset` reference (via `useCallback`) — the hook re-attaches listeners whenever `reset`'s identity changes. - `blur` fires even when `visibilitychange` does not (e.g., a second window focused alongside this tab), making both listeners necessary. - On `blur` without tab hiding, the marquee may briefly resume under a stationary cursor in the unfocused window; it re-pauses on the next `pointermove`/`pointerenter`. - Intended as the single wiring point (SSOT) for all marquee surfaces (`MarqueeWall`, `CardsStrip`). **Source:** [`use-reset-on-page-hidden.ts`](https://github.com/flamingo-stack/openframe-oss-lib/blob/main/use-reset-on-page-hidden.ts)