Fix update notifications (#1387)
* Fix service worker reloading error * Fix syntax
This commit is contained in:
parent
dbaed5478a
commit
5fe4575d3d
1 changed files with 5 additions and 3 deletions
|
@ -18,10 +18,12 @@ export const useServiceWorker = (timeout: number) => {
|
||||||
registrationRef.current = registration;
|
registrationRef.current = registration;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUpdateFound = () => setUpdateAvailable(true);
|
const onUpdate = (registration: ServiceWorkerRegistration) => {
|
||||||
|
setUpdateAvailable(!!registration?.waiting);
|
||||||
|
};
|
||||||
|
|
||||||
const update = useCallback(() => {
|
const update = useCallback(() => {
|
||||||
if (updateAvailable) {
|
if (updateAvailable && registrationRef.current?.waiting) {
|
||||||
registrationRef.current.waiting.postMessage("update");
|
registrationRef.current.waiting.postMessage("update");
|
||||||
}
|
}
|
||||||
}, [updateAvailable]);
|
}, [updateAvailable]);
|
||||||
|
@ -29,7 +31,7 @@ export const useServiceWorker = (timeout: number) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
register("/sw.js", {
|
register("/sw.js", {
|
||||||
registered: onRegistered,
|
registered: onRegistered,
|
||||||
updatefound: onUpdateFound
|
updated: onUpdate
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue