From b854b76e7e86c5a0d065d4d7fa921208be05c2bc Mon Sep 17 00:00:00 2001 From: Marco Supino Date: Fri, 26 Jun 2026 19:50:40 +0300 Subject: [PATCH 1/3] fix(persist): store empty route as absent key, not an empty object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After clear-store reload (or a fresh boot), the app re-persisted an empty '{waypoints:[],legs:[],notes:[]}' to navaid.route, so the clear-store test's null check flaked on timing. persist/flushPersist now remove the key when the route is empty instead of writing an empty object — deterministic 'cleared' state. Fixes the recurring clear-store.spec.js CI flake. --- docs/app/io.js | 16 ++++++++++++++-- docs/index.html | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/app/io.js b/docs/app/io.js index bf7b9eb5..f767ca75 100644 --- a/docs/app/io.js +++ b/docs/app/io.js @@ -3771,6 +3771,18 @@ async function flyRoute() { const STORE_KEY = 'navaid.route'; let persistTimer = null; let quotaWarned = false; // #80: stop scheduling after a quota fail +// An empty route is stored as the *absence* of the key, not an empty object, so +// a fresh boot (or a clear-store reload) leaves navaid.route truly cleared +// rather than re-writing "{waypoints:[]…}". +function routeIsEmpty() { + return state.waypoints.length === 0 && + state.legs.length === 0 && + state.notes.length === 0; +} +function writeRoute() { + if (routeIsEmpty()) localStorage.removeItem(STORE_KEY); + else localStorage.setItem(STORE_KEY, JSON.stringify(routeSnapshotForStorage())); +} function persist() { // When boot detected a corrupt saved blob (issue #73), refuse to overwrite // it with the empty in-memory state — that's silent data loss. Once the @@ -3789,7 +3801,7 @@ function persist() { persistTimer = null; try { // center / zoom are not restored (load fits the route) — not saved. - localStorage.setItem(STORE_KEY, JSON.stringify(routeSnapshotForStorage())); + writeRoute(); } catch (e) { // #80: a full quota used to fail silently. Surface it once so the // user knows to export the route; other storage-unavailable errors @@ -3814,7 +3826,7 @@ function flushPersist() { } if (quotaWarned) return; try { - localStorage.setItem(STORE_KEY, JSON.stringify(routeSnapshotForStorage())); + writeRoute(); } catch (e) { if (e && (e.name === 'QuotaExceededError' || e.code === 22 || e.code === 1014 /* NS_ERROR_DOM_QUOTA_REACHED */)) { diff --git a/docs/index.html b/docs/index.html index 89dcb315..388ba7b6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -120,7 +120,7 @@ - +