From 019cbd0b00dce3829d7f439291d73e08780a35d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 06:36:39 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(nav):=20the=20swap=20settles?= =?UTF-8?q?=20the=20URL=20before=20it=20runs=20the=20new=20page's=20script?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `swap()` replaced the body — which re-executes the swapped-in page's inline scripts — and only then rewrote the address bar. `logs.rs`'s fit script reads `location.href` and reloads through it, so it read the page the browser had just left: pressing Logs painted the page and then hard-navigated back to the board a couple of hundred milliseconds later. The second press worked, its `sessionStorage` fit guard now set, which is why this looked like a render glitch rather than a bug. History and the `` attributes now move before the body swap, and the link handler pushes through `swap` instead of after it. Two guards, both mutation-checked against the old ordering: an ordering assertion over the served script in `tests/http.rs`, and `tests/browser/` — a real Chromium that presses Logs twice, the second press having to be a swap with no document load. Playwright stays out of the repo; the runner installs it once into `~/.cache/izlek/browser-tests`. --- crates/izlek-web/src/layout.rs | 27 ++-- crates/izlek-web/tests/browser/run.sh | 64 +++++++++ crates/izlek-web/tests/browser/soft-nav.mjs | 139 ++++++++++++++++++++ crates/izlek-web/tests/http.rs | 55 ++++++++ 4 files changed, 274 insertions(+), 11 deletions(-) create mode 100755 crates/izlek-web/tests/browser/run.sh create mode 100644 crates/izlek-web/tests/browser/soft-nav.mjs diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index 1b0ec4d..b535195 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -142,6 +142,11 @@ pub async fn topbar_nav(cx: &Cx, active: NavPage, role: izlek_core::Role, lang: /// arrive with the swap because the redirect URL's query params rendered /// them server-side; `history.replaceState` keeps the address bar honest. /// +/// The address bar and the `` attributes are rewritten *before* the +/// new body's scripts run, never after: a swapped-in script that reads +/// `location.href` (the log-fit reload in `logs.rs`) would otherwise read +/// the page it just replaced and hard-navigate back to it. +/// /// Swapped-in `