From ab851d4bb1a63c8a6e44ab85ac940cdc5161e48d Mon Sep 17 00:00:00 2001 From: rene Date: Sat, 9 May 2026 20:58:07 +0200 Subject: [PATCH] Fix: SW updatefound Listener vor reg.update() + race condition safety (SW by-v804) --- backend/main.py | 2 +- backend/static/index.html | 13 +++++++------ backend/static/js/app.js | 2 +- backend/static/sw.js | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/main.py b/backend/main.py index b9905ab..ba006bc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -341,7 +341,7 @@ MEDIA_DIR = os.getenv("MEDIA_DIR", "/data/media") os.makedirs(MEDIA_DIR, exist_ok=True) app.mount("/media", StaticFiles(directory=MEDIA_DIR), name="media") -APP_VER = "803" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "804" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/static/index.html b/backend/static/index.html index 46ced7b..da2b50c 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -628,18 +628,19 @@ window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js', { updateViaCache: 'none' }) .then(reg => { - reg.update(); - - // Primär: neuer SW hat aktiviert → sofort neu laden - reg.addEventListener('updatefound', () => { - const sw = reg.installing; + function _watchSW(sw) { if (!sw) return; sw.addEventListener('statechange', () => { if (sw.state === 'activated') { window.location.replace('/?_t=' + Date.now()); } }); - }); + } + // Listener VOR update() registrieren — verhindert Race Condition + reg.addEventListener('updatefound', () => _watchSW(reg.installing)); + // Falls SW bereits installiert (Seite wurde nach SW-Install neu geladen) + if (reg.installing) _watchSW(reg.installing); + reg.update(); }) .catch(err => console.warn('SW Registration failed:', err)); }); diff --git a/backend/static/js/app.js b/backend/static/js/app.js index d10de0d..0f083d8 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '803'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '804'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.5.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; // Cache-Bust-Parameter nach Update-Reload sofort entfernen diff --git a/backend/static/sw.js b/backend/static/sw.js index 6ae794e..37b78ee 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -3,7 +3,7 @@ Offline-Cache + Push Notifications + Tile-Cache ============================================================ */ -const CACHE_VERSION = 'by-v803'; +const CACHE_VERSION = 'by-v804'; const CACHE_STATIC = `${CACHE_VERSION}-static`; const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache