diff --git a/packages/webui/src/components/login-waves.tsx b/packages/webui/src/components/login-waves.tsx index f6e9506f..233ed2ac 100644 --- a/packages/webui/src/components/login-waves.tsx +++ b/packages/webui/src/components/login-waves.tsx @@ -89,6 +89,10 @@ export function LoginWaves() { let lines: Pt[][] = []; let paths: SVGPathElement[] = []; let raf = 0; + // Honour reduced-motion (the OS setting or the app's own data-reduce-motion + // toggle): draw a single static frame instead of running the rAF loop. #185. + const prefersReduced = window.matchMedia('(prefers-reduced-motion: reduce)'); + const reduced = () => prefersReduced.matches || document.documentElement.dataset.reduceMotion === '1'; const setSize = () => { bounding = host.getBoundingClientRect(); @@ -143,7 +147,7 @@ export function LoginWaves() { const t = e.touches[0]; if (t) updateMouse(t.clientX, t.clientY); }; - const onResize = () => { setSize(); setLines(); }; + const onResize = () => { setSize(); setLines(); if (reduced()) { movePoints(0); drawLines(); } }; const movePoints = (time: number) => { lines.forEach((points) => { @@ -213,10 +217,23 @@ export function LoginWaves() { window.addEventListener('resize', onResize); window.addEventListener('mousemove', onMouseMove); window.addEventListener('touchmove', onTouchMove, { passive: true }); - raf = requestAnimationFrame(tick); + // Animate only when motion is allowed; otherwise paint one static frame. + // React live to changes of the OS reduced-motion preference. + const applyMotion = () => { + if (reduced()) { + if (raf) { cancelAnimationFrame(raf); raf = 0; } + movePoints(0); + drawLines(); + } else if (!raf) { + raf = requestAnimationFrame(tick); + } + }; + prefersReduced.addEventListener('change', applyMotion); + applyMotion(); return () => { cancelAnimationFrame(raf); + prefersReduced.removeEventListener('change', applyMotion); window.removeEventListener('resize', onResize); window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('touchmove', onTouchMove); diff --git a/packages/webui/src/components/overview/deliveries-widget.tsx b/packages/webui/src/components/overview/deliveries-widget.tsx index 89a252ed..5d5ace7c 100644 --- a/packages/webui/src/components/overview/deliveries-widget.tsx +++ b/packages/webui/src/components/overview/deliveries-widget.tsx @@ -18,7 +18,12 @@ export function DeliveriesWidget() { useEffect(() => { let active = true; - const pull = () => + let inFlight = false; + const pull = () => { + // Skip while the tab is backgrounded, or if a request is still in flight + // (a slow endpoint must not stack overlapping polls). #185. + if (inFlight || document.hidden) return; + inFlight = true; api.notifications .recent(50) .then((r) => { @@ -26,12 +31,19 @@ export function DeliveriesWidget() { }) .catch(() => { if (active) setRecords((prev) => prev ?? []); - }); + }) + .finally(() => { inFlight = false; }); + }; void pull(); const id = window.setInterval(() => void pull(), POLL_MS); + // The interval keeps firing but no-ops while hidden, so refresh immediately + // when the tab becomes visible again to shed any staleness. + const onVisible = () => { if (!document.hidden) pull(); }; + document.addEventListener('visibilitychange', onVisible); return () => { active = false; window.clearInterval(id); + document.removeEventListener('visibilitychange', onVisible); }; }, [api]);