OH12: defer browser-offline until mount for saved-filter e2e

useBrowserOffline now returns false through SSR/hydration so online
controls (Salvar filtro) stay clickable; OfflineBoundary Local swap still
waits for mount + navigator.onLine.
This commit is contained in:
Cursor Agent 2026-08-02 01:51:27 +00:00
parent a186648c1f
commit 0e4cfc545d
No known key found for this signature in database

View file

@ -2,16 +2,23 @@
import { useEffect, useState } from 'react'
/** Browser online/offline only — matches OfflineBoundary Local trigger. */
/**
* Browser online/offline only — matches OfflineBoundary Local trigger.
*
* Returns false until mount so SSR/hydration and first paint stay on the
* online controls (saved-filter create, etc.). After mount, follows
* `navigator.onLine`.
*/
export const useBrowserOffline = (): boolean => {
const [offline, setOffline] = useState(() =>
typeof navigator !== 'undefined' ? !navigator.onLine : false,
)
const [mounted, setMounted] = useState(false)
const [offline, setOffline] = useState(false)
useEffect(() => {
setMounted(true)
setOffline(!navigator.onLine)
const onOnline = () => setOffline(false)
const onOffline = () => setOffline(true)
setOffline(!navigator.onLine)
window.addEventListener('online', onOnline)
window.addEventListener('offline', onOffline)
return () => {
@ -20,5 +27,5 @@ export const useBrowserOffline = (): boolean => {
}
}, [])
return offline
return mounted && offline
}