From 4e3e5506aad9a2b95114f582efa40c97e01eefa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 03:05:44 +0300 Subject: [PATCH] =?UTF-8?q?fix(web):=20a=20reload=20cuts=20a=20live=20flig?= =?UTF-8?q?ht=20dead,=20so=20the=20browser's=20leave-confirm=20asks=20firs?= =?UTF-8?q?t=20=E2=80=94=20beforeunload=20reads=20the=20upload=20mirror=20?= =?UTF-8?q?at=20ask=20time,=20done=20records=20never=20hold=20the=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/in-web/src/drive.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/in-web/src/drive.rs b/crates/in-web/src/drive.rs index 993993b..0ef838b 100644 --- a/crates/in-web/src/drive.rs +++ b/crates/in-web/src/drive.rs @@ -919,6 +919,10 @@ fn query_value(query: &str, key: &str) -> Option { /// drops it from the stack and the mirror, so the record lingers exactly /// as long as the reader wants it. /// +/// While a flight is live, leaving the page — reload above all — is +/// intercepted by the browser's own confirm (`beforeunload` reading the +/// mirror at ask time, so it never asks for a row that has already landed). +/// /// The form wears `data-hard` so the soft-nav's multipart replay leaves it /// alone — two uploaders racing the same bytes would double-insert, and the /// progress the soft-nav draws knows nothing of chunks. Without script the @@ -1079,6 +1083,17 @@ async fn upload_script(cx: &Cx) -> Result { function finishRow(u) { u.done = true; renderUploads(); } \ document.addEventListener('in:wire', renderUploads); \ renderUploads(); \ + /* A reload cuts a flight dead — the small path's XHR dies \ + unrecoverable, and the chunked walk, though it can resume, \ + stops mid-air — so the browser's own leave-confirm asks \ + first. The guard is armed once and reads the mirror at ask \ + time, so there is no arm/disarm bookkeeping to forget; a \ + done row is only a record and never holds the page \ + hostage. */ \ + window.addEventListener('beforeunload', function (ev) { \ + var flying = (window.__inUploads || []).some(function (u) { return !u.done; }); \ + if (flying) { ev.preventDefault(); ev.returnValue = ''; } \ + }); \ function notify(kind, message) { \ if (window.__inNotify) { window.__inNotify(kind, message); } \ } \