🐛(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:
@@ -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
|
||||
|
||||
|
||||
@@ -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>) => {
|
||||
|
||||
Reference in New Issue
Block a user