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;
|
||||
};
|
||||
|
||||
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
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
|
Loading…
Reference in a new issue