A reload cuts a live flight dead, so the browser's leave-confirm asks first — beforeunload reads the upload mirror at ask time, done records never hold the page
Browse files at this commit4e3e5506aad9a2b95114f582efa40c97e01eefa9Parent: 6cb90b4- fix
- a reload cuts a live flight dead, so the browser's leave-confirm asks first — beforeunload reads the upload mirror at ask time, done records never hold the page
1 changed file +15 -0
- crates/in-web/src/drive.rs +15 -0
crates/in-web/src/drive.rsmodified+15 -0
| @@ -919,6 +919,10 @@ fn query_value(query: &str, key: &str) -> Option<String> { | ||
| 919 | 919 | /// drops it from the stack and the mirror, so the record lingers exactly |
| 920 | 920 | /// as long as the reader wants it. |
| 921 | 921 | /// |
| 922 | +/// While a flight is live, leaving the page — reload above all — is | |
| 923 | +/// intercepted by the browser's own confirm (`beforeunload` reading the | |
| 924 | +/// mirror at ask time, so it never asks for a row that has already landed). | |
| 925 | +/// | |
| 922 | 926 | /// The form wears `data-hard` so the soft-nav's multipart replay leaves it |
| 923 | 927 | /// alone — two uploaders racing the same bytes would double-insert, and the |
| 924 | 928 | /// progress the soft-nav draws knows nothing of chunks. Without script the |
| @@ -1079,6 +1083,17 @@ async fn upload_script(cx: &Cx) -> Result { | ||
| 1079 | 1083 | function finishRow(u) { u.done = true; renderUploads(); } \ |
| 1080 | 1084 | document.addEventListener('in:wire', renderUploads); \ |
| 1081 | 1085 | renderUploads(); \ |
| 1086 | + /* A reload cuts a flight dead — the small path's XHR dies \ | |
| 1087 | + unrecoverable, and the chunked walk, though it can resume, \ | |
| 1088 | + stops mid-air — so the browser's own leave-confirm asks \ | |
| 1089 | + first. The guard is armed once and reads the mirror at ask \ | |
| 1090 | + time, so there is no arm/disarm bookkeeping to forget; a \ | |
| 1091 | + done row is only a record and never holds the page \ | |
| 1092 | + hostage. */ \ | |
| 1093 | + window.addEventListener('beforeunload', function (ev) { \ | |
| 1094 | + var flying = (window.__inUploads || []).some(function (u) { return !u.done; }); \ | |
| 1095 | + if (flying) { ev.preventDefault(); ev.returnValue = ''; } \ | |
| 1096 | + }); \ | |
| 1082 | 1097 | function notify(kind, message) { \ |
| 1083 | 1098 | if (window.__inNotify) { window.__inNotify(kind, message); } \ |
| 1084 | 1099 | } \ |