From 32fde79a409b464529d729a793bcd82359ded261 Mon Sep 17 00:00:00 2001 From: rene Date: Fri, 15 May 2026 17:56:29 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20=5Fqueued-Guard=20in=20poison/walks/diar?= =?UTF-8?q?y=20=E2=80=94=20kein=20Crash=20bei=20SW-gequeuten=20Requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wenn der SW einen POST in die Offline-Queue legt, gibt api.js { _queued: true } zurück (202). Ohne Guard versuchten poison/walks/diary den Response als echtes Server-Objekt zu nutzen → undefined lat/lon → Leaflet-Crash, undefined id → Upload-Fehler. Nach dem Guard wird das Modal nur geschlossen; der QUEUE_PROCESSED-Toast informiert den User sobald synchronisiert. - poison.js: _queued guard nach API.poison.report() - walks.js: _queued guard + try-catch statt navigator.onLine - diary.js: _queued guard nach API.diary.create() - SW by-v992, APP_VER 992 --- backend/main.py | 2 +- backend/static/js/app.js | 2 +- backend/static/js/pages/diary.js | 1 + backend/static/js/pages/poison.js | 3 +++ backend/static/js/pages/walks.js | 20 +++++++++++++------- backend/static/sw.js | 2 +- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/backend/main.py b/backend/main.py index ccf969b..e5e68dc 100644 --- a/backend/main.py +++ b/backend/main.py @@ -410,7 +410,7 @@ async def serve_media(path: str, request: _Request): raise _HE(404, "Nicht gefunden.") return _media_response(filepath) -APP_VER = "991" # muss mit APP_VER in app.js übereinstimmen +APP_VER = "992" # muss mit APP_VER in app.js übereinstimmen @app.get("/.well-known/assetlinks.json") async def assetlinks(): diff --git a/backend/static/js/app.js b/backend/static/js/app.js index 7fdd413..28492bb 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 = '991'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '992'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.6.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/js/pages/diary.js b/backend/static/js/pages/diary.js index c708912..d15c9b5 100644 --- a/backend/static/js/pages/diary.js +++ b/backend/static/js/pages/diary.js @@ -1765,6 +1765,7 @@ window.Page_diary = (() => { UI.toast.success('Eintrag gespeichert.'); } else { const created = await API.diary.create(_appState.activeDog.id, payload); + if (created?._queued) { UI.modal.close(); return; } if (_newFiles.length > 0) { const { uploaded, exifGps } = await _uploadNewFiles(created.id); created.media_items = uploaded; diff --git a/backend/static/js/pages/poison.js b/backend/static/js/pages/poison.js index 5af9a34..f4b1dd4 100644 --- a/backend/static/js/pages/poison.js +++ b/backend/static/js/pages/poison.js @@ -543,6 +543,9 @@ window.Page_poison = (() => { const created = await API.poison.report(payload); + // SW hat Request in Queue gelegt (offline) — Modal schließen, kein Marker + if (created?._queued) { UI.modal.close(); return; } + // Foto hochladen if (photoInput?.files[0]) { try { diff --git a/backend/static/js/pages/walks.js b/backend/static/js/pages/walks.js index feaeb62..e0c6c40 100644 --- a/backend/static/js/pages/walks.js +++ b/backend/static/js/pages/walks.js @@ -1186,14 +1186,20 @@ window.Page_walks = (() => { _renderList(); _renderMarkers(); } else { - if (!navigator.onLine) { - _addPending(payload); - UI.modal.close(); - UI.toast.success('Offline gespeichert — wird synchronisiert sobald Verbindung besteht.'); - _loadData(); - return; + let created; + try { + created = await API.walks.create(payload); + } catch (netErr) { + if (netErr instanceof TypeError || !navigator.onLine) { + _addPending(payload); + UI.modal.close(); + UI.toast.success('Offline gespeichert — wird synchronisiert sobald Verbindung besteht.'); + _loadData(); + return; + } + throw netErr; } - const created = await API.walks.create(payload); + if (created?._queued) { UI.modal.close(); _loadData(); return; } _data.unshift({ ...created, teilnehmer_count: 0 }); UI.toast.success('Treffen geplant! 🎉'); UI.modal.close(); diff --git a/backend/static/sw.js b/backend/static/sw.js index d451c5b..cee7de1 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-v991'; +const CACHE_VERSION = 'by-v992'; 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