fix(pwa): make web updates deterministic (#1093)

* fix(pwa): make web updates deterministic

* fix(pwa): address review feedback
This commit is contained in:
Tommaso Casaburi
2026-03-17 16:20:13 +08:00
committed by GitHub
parent b2946e8b2e
commit f812fe1d18
11 changed files with 235 additions and 27 deletions
@@ -0,0 +1,46 @@
import { useEffect } from 'react';
import packageJson from '../../../package.json';
import { fetchLatestStableVersion, isElectron, refreshServiceWorkerRegistration } from '../../lib/app-update';
import useAppUpdateStore from '../../stores/use-app-update-store';
const UPDATE_CHECK_INTERVAL_MS = 60 * 1000;
const AppUpdateRegistration = () => {
useEffect(() => {
if (isElectron) {
return undefined;
}
let isDisposed = false;
const syncUpdateAvailability = async () => {
await refreshServiceWorkerRegistration().catch((error) => {
console.error('Failed to refresh service worker registration', error);
});
try {
const latestStableVersion = await fetchLatestStableVersion();
if (!isDisposed) {
useAppUpdateStore.getState().setNeedRefresh(packageJson.version !== latestStableVersion);
}
} catch (error) {
console.error('Failed to check app update availability', error);
}
};
void syncUpdateAvailability();
const intervalId = window.setInterval(() => {
void syncUpdateAvailability();
}, UPDATE_CHECK_INTERVAL_MS);
return () => {
isDisposed = true;
window.clearInterval(intervalId);
useAppUpdateStore.getState().setNeedRefresh(false);
};
}, []);
return null;
};
export default AppUpdateRegistration;
@@ -0,0 +1 @@
export { default } from './app-update-registration';