forge
Explore
Log in

Don't you dare go Hollow

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 commit

4e3e5506aad9a2b95114f582efa40c97e01eefa9Ahmet Kaan GümüşParent: 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
Show full message
fix(web): 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
crates/in-web/src/drive.rsmodified+15 -0
@@ -919,6 +919,10 @@ fn query_value(query: &str, key: &str) -> Option<String> {
919 /// drops it from the stack and the mirror, so the record lingers exactly919 /// drops it from the stack and the mirror, so the record lingers exactly
920 /// as long as the reader wants it.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 /// The form wears `data-hard` so the soft-nav's multipart replay leaves it926 /// The form wears `data-hard` so the soft-nav's multipart replay leaves it
923 /// alone — two uploaders racing the same bytes would double-insert, and the927 /// alone — two uploaders racing the same bytes would double-insert, and the
924 /// progress the soft-nav draws knows nothing of chunks. Without script the928 /// progress the soft-nav draws knows nothing of chunks. Without script the
@@ -1079,6 +1083,17 @@ async fn upload_script(cx: &Cx) -> Result {
1079 function finishRow(u) { u.done = true; renderUploads(); } \1083 function finishRow(u) { u.done = true; renderUploads(); } \
1080 document.addEventListener('in:wire', renderUploads); \1084 document.addEventListener('in:wire', renderUploads); \
1081 renderUploads(); \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 function notify(kind, message) { \1097 function notify(kind, message) { \
1083 if (window.__inNotify) { window.__inNotify(kind, message); } \1098 if (window.__inNotify) { window.__inNotify(kind, message); } \
1084 } \1099 } \