chore(ui): delete unused usePageVisible hook

Added as a reusable primitive during Plan 03 Task 9, but the intended
consumer (NotificationBell live-region refresh) was removed during
code review, leaving the hook unused. Delete it — YAGNI; reintroduce
when a real consumer shows up.

Verified upstream impact (gitnexus): 0 callers, LOW risk.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-20 18:02:04 +02:00
parent ec460faf02
commit 579b5f1a04
2 changed files with 0 additions and 52 deletions

View File

@@ -1,30 +0,0 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { renderHook, act } from '@testing-library/react';
import { usePageVisible } from './usePageVisible';
describe('usePageVisible', () => {
beforeEach(() => {
Object.defineProperty(document, 'visibilityState', {
value: 'visible',
configurable: true,
writable: true,
});
});
it('returns true when visible, false when hidden', () => {
const { result } = renderHook(() => usePageVisible());
expect(result.current).toBe(true);
act(() => {
Object.defineProperty(document, 'visibilityState', { value: 'hidden', configurable: true });
document.dispatchEvent(new Event('visibilitychange'));
});
expect(result.current).toBe(false);
act(() => {
Object.defineProperty(document, 'visibilityState', { value: 'visible', configurable: true });
document.dispatchEvent(new Event('visibilitychange'));
});
expect(result.current).toBe(true);
});
});

View File

@@ -1,22 +0,0 @@
import { useEffect, useState } from 'react';
/**
* Tracks Page Visibility API state for the current document.
*
* Returns `true` when the tab is visible, `false` when hidden. Useful for
* pausing work (polling, animations, expensive DOM effects) while the tab
* is backgrounded. SSR-safe: defaults to `true` when `document` is undefined.
*/
export function usePageVisible(): boolean {
const [visible, setVisible] = useState(() =>
typeof document === 'undefined' ? true : document.visibilityState === 'visible',
);
useEffect(() => {
const onChange = () => setVisible(document.visibilityState === 'visible');
document.addEventListener('visibilitychange', onChange);
return () => document.removeEventListener('visibilitychange', onChange);
}, []);
return visible;
}