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 {
|
export function registerAppServiceWorker(): void {
|
||||||
if (started || typeof window === 'undefined' || !('serviceWorker' in navigator)) return;
|
if (started || typeof window === 'undefined' || !('serviceWorker' in navigator)) return;
|
||||||
if (Capacitor.isNativePlatform()) {
|
if (Capacitor.isNativePlatform()) {
|
||||||
// The native shell must never inherit an old web app-shell worker.
|
// The native shell must never inherit an old web app-shell worker. Some
|
||||||
if ('serviceWorker' in navigator) {
|
// Android WebViews expose a partial/absent Service Worker API, so every
|
||||||
void navigator.serviceWorker.getRegistrations()
|
// call is feature-checked and wrapped — this cleanup must never abort React
|
||||||
.then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } }))
|
// boot (that produced a black screen after the native splash).
|
||||||
.catch(() => undefined);
|
try {
|
||||||
}
|
if (navigator.serviceWorker && typeof navigator.serviceWorker.getRegistrations === 'function') {
|
||||||
if (typeof caches !== 'undefined') {
|
void navigator.serviceWorker.getRegistrations()
|
||||||
void caches.keys()
|
.then((regs) => regs.forEach((reg) => { try { reg.unregister(); } catch { /* ignore */ } }))
|
||||||
.then((keys) => keys.filter((key) => key.startsWith('skate-spots-shell-'))
|
.catch(() => undefined);
|
||||||
.forEach((key) => { void caches.delete(key).catch(() => undefined); }))
|
}
|
||||||
.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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue