From 489c34d2f237c2cba43ced4141bed84448ddf83f Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 8 Jun 2026 09:15:43 -0400 Subject: [PATCH] Nav Back: track popstate delta so back-then-forward keeps accurate depth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex's remaining caveat: appNavDepth decremented on every popstate, so a browser Back then Forward undercounted (in-page Back would jump to Highlights early). Use the navigation's signed delta on popstate (Back -1, Forward +1, ±N for jumps) instead of a flat decrement, so the depth stays accurate through any back/forward dance. Falls back to -1 if delta is unavailable (safe). Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/routes/+page.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index b11cd05..dde7ee2 100644 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -276,10 +276,11 @@ // The initial 'enter' is handled by onMount, after its data deps are fetched. afterNavigate((nav) => { if (nav.type === 'enter') return; - // Forward in-app nav deepens the stack; back/forward (popstate) unwinds it. - // Clamped at 0, so an out-of-app landing keeps Back app-safe (→ Highlights). + // Forward in-app nav deepens the stack; popstate moves by its signed delta + // (Back = -1, Forward = +1, ±N for jumps), so a back-then-forward dance keeps + // an accurate count. Clamped at 0, so an out-of-app landing stays app-safe. if (nav.type === 'goto' || nav.type === 'link') appNavDepth += 1; - else if (nav.type === 'popstate') appNavDepth = Math.max(0, appNavDepth - 1); + else if (nav.type === 'popstate') appNavDepth = Math.max(0, appNavDepth + (nav.delta ?? -1)); loadView(selected); });