mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
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:
parent
a186648c1f
commit
0e4cfc545d
1 changed files with 13 additions and 6 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue