Fix update notifications (#1387)

* Fix service worker reloading error

* Fix syntax
This commit is contained in:
Dominik Żegleń 2021-09-14 11:06:28 +02:00 committed by GitHub
parent dbaed5478a
commit 5fe4575d3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,10 +18,12 @@ export const useServiceWorker = (timeout: number) => {
registrationRef.current = registration;
};
const onUpdateFound = () => setUpdateAvailable(true);
const onUpdate = (registration: ServiceWorkerRegistration) => {
setUpdateAvailable(!!registration?.waiting);
};
const update = useCallback(() => {
if (updateAvailable) {
if (updateAvailable && registrationRef.current?.waiting) {
registrationRef.current.waiting.postMessage("update");
}
}, [updateAvailable]);
@ -29,7 +31,7 @@ export const useServiceWorker = (timeout: number) => {
useEffect(() => {
register("/sw.js", {
registered: onRegistered,
updatefound: onUpdateFound
updated: onUpdate
});
}, []);