fix: never abort native boot on service-worker cleanup
This commit is contained in:
parent
9dd2231332
commit
267e93abc7
1 changed files with 18 additions and 11 deletions
|
|
@ -12,17 +12,24 @@ let started = false;
|
|||
export function registerAppServiceWorker(): void {
|
||||
if (started || typeof window === 'undefined' || !('serviceWorker' in navigator)) return;
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
// The native shell must never inherit an old web app-shell worker.
|
||||
if ('serviceWorker' in navigator) {
|
||||
void navigator.serviceWorker.getRegistrations()
|
||||
.then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } }))
|
||||
.catch(() => undefined);
|
||||
}
|
||||
if (typeof caches !== 'undefined') {
|
||||
void caches.keys()
|
||||
.then((keys) => keys.filter((key) => key.startsWith('skate-spots-shell-'))
|
||||
.forEach((key) => { void caches.delete(key).catch(() => undefined); }))
|
||||
.catch(() => undefined);
|
||||
// The native shell must never inherit an old web app-shell worker. Some
|
||||
// Android WebViews expose a partial/absent Service Worker API, so every
|
||||
// call is feature-checked and wrapped — this cleanup must never abort React
|
||||
// boot (that produced a black screen after the native splash).
|
||||
try {
|
||||
if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') {
|
||||
void navigator.serviceWorker.getRegistrations()
|
||||
.then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } }))
|
||||
.catch(() => undefined);
|
||||
}
|
||||
if (typeof caches !== 'undefined' && typeof caches.keys === 'function') {
|
||||
void caches.keys()
|
||||
.then((keys) => keys.filter((key) => key.startsWith('skate-spots-shell-'))
|
||||
.forEach((key) => { void caches.delete(key).catch(() => undefined); }))
|
||||
.catch(() => undefined);
|
||||
}
|
||||
} catch {
|
||||
// Best-effort only; boot must continue.
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue