fix(pwa): Updates zuverlässiger erkennen und veraltete Instanzen automatisch reparieren

Unabhängige version.json-Prüfung, häufigere Update-Checks und Hard Recovery
beheben hängende Android-PWAs ohne manuelles Cache-Löschen.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-31 14:20:54 +02:00
parent d2833f7664
commit bbd4281dcb
9 changed files with 396 additions and 33 deletions
+32 -2
View File
@@ -2,7 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import {
markReloadAttempt,
recentlyAttemptedReload,
reconcileServiceWorkerOnStartup
reconcileServiceWorkerOnStartup,
reconcileVersionOnStartup
} from './pwaStartup.js'
describe('pwaStartup reload guards', () => {
@@ -35,7 +36,12 @@ describe('reconcileServiceWorkerOnStartup', () => {
configurable: true,
value: {
controller: {},
getRegistration: vi.fn().mockResolvedValue({ waiting: null }),
getRegistration: vi.fn().mockResolvedValue({
waiting: null,
installing: null,
update: vi.fn().mockResolvedValue(undefined),
addEventListener: vi.fn()
}),
addEventListener: vi.fn()
}
})
@@ -43,3 +49,27 @@ describe('reconcileServiceWorkerOnStartup', () => {
await expect(reconcileServiceWorkerOnStartup()).resolves.toBe(false)
})
})
describe('reconcileVersionOnStartup', () => {
beforeEach(() => {
sessionStorage.clear()
vi.unstubAllEnvs()
vi.restoreAllMocks()
})
it('returns noop in dev mode', async () => {
vi.stubEnv('DEV', true)
await expect(reconcileVersionOnStartup()).resolves.toBe('noop')
})
it('returns noop when deployed version matches bundled version', async () => {
vi.stubEnv('DEV', false)
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ version: '0.1.0.57' })
}))
vi.stubGlobal('__APP_VERSION__', '0.1.0.57')
await expect(reconcileVersionOnStartup()).resolves.toBe('noop')
})
})