🐛(service-worker) Fix useOffline Maximum update depth exceeded

Sentry was reporting a "Maximum update depth exceeded" error
comming from the `useOffline` hook. We updated the hook to
avoid mutation. Seems to impact mainly edge browsers.
This commit is contained in:
Anthony LC
2025-07-17 16:48:03 +02:00
parent 040eddbe6b
commit 5a23c97681
2 changed files with 13 additions and 5 deletions

View File

@@ -8,8 +8,13 @@ and this project adheres to
## [Unreleased]
## Fixed
### Changed
- 🔧(project) change env.d system by using local files #1200
### Fixed
- 🐛(service-worker) Fix useOffline Maximum update depth exceeded #1196
- 🐛(helm) charts generate invalid YAML for collaboration API / WS #890
## [3.4.2] - 2025-07-18
@@ -17,7 +22,6 @@ and this project adheres to
### Changed
- ⚡️(docker) Optimize Dockerfile to use apk with --no-cache #743
- 🔧(project) change env.d system by using local files #1200
### Fixed

View File

@@ -14,13 +14,17 @@ interface IsOfflineState {
setIsOffline: (value: boolean) => void;
}
export const useIsOffline = create<IsOfflineState>((set) => ({
export const useIsOffline = create<IsOfflineState>((set, get) => ({
isOffline: typeof navigator !== 'undefined' && !navigator.onLine,
setIsOffline: (value: boolean) => set({ isOffline: value }),
setIsOffline: (value: boolean) => {
if (get().isOffline !== value) {
set({ isOffline: value });
}
},
}));
export const useOffline = () => {
const { setIsOffline } = useIsOffline();
const setIsOffline = useIsOffline((state) => state.setIsOffline);
useEffect(() => {
const handleMessage = (event: MessageEvent<OfflineMessageData>) => {