web: harden drop-open and autosave after adversarial review

Review of the drop-open and autosave commits surfaced one blocker and
five majors; all are fixed here, and two claims in the autosave commit
message are corrected by this one: tab close does NOT clear a snapshot
(matches native .sv$ semantics — saving, restoring, discarding, exit,
and the capped boot scan do), and serialization runs on the main
thread between awaits, not off the paint path.

- The restore prompt can no longer appear with no entries (empty
  "Recover Drawing" modal on every boot once the autosave dir exists).
- Restore no longer consumes the snapshot before the open succeeds:
  the recovered drawing goes through the guarded drop queue, and the
  snapshot is deleted only after the tab opens; cancel or parse
  failure keeps the only copy.
- Saving during an autosave round defers its snapshot cleanup until
  the round finishes, so a stale round can no longer resurrect a
  snapshot newer than the save.
- The boot scan no longer deletes snapshots by mtime comparison
  (re-opening a drawing refreshes the recent copy's mtime, which
  silently destroyed wanted snapshots); GC is now a 16-entry cap with
  oldest-first eviction.
- OPFS write failures abort the writable stream (a leaked lock could
  stall the same-key writer and disable autosave for the session), and
  DOMException errors now carry their name/message.
- Empty (crash-window) snapshots are never offered; an unreadable one
  warns and stays discardable instead of looping forever.
- Drop-open polish: reads start inside the handler and complete in
  drop order (legacy WebKit safety, deterministic multi-file order),
  dragenter is canceled too, the install guard only latches on
  success, non-drawing drops don't steal propagation, a lock-poison
  panic can't cross into JS, and re-dropping an open drawing no
  longer risks clobbering an in-flight open (it re-queues).
- The model-space sheet floor is per-axis (a thin 8x400 mm profile
  keeps its length) and centers content on the enlarged page.
This commit is contained in:
Afonsop committed 2026-09-16 10:22:25 +01:00
1 parent 101d167ebc
commit 3edbc5b7c8
8 files changed
+386 -118

No files matched your search

+19 -5
View File
@@ -26,14 +26,21 @@ impl OpenCADStudio {
/// Queue the web crash-recovery prompt behind whatever startup modal is
/// already showing (donation, GPU warning…); the after-message hook in
/// `update` surfaces it as soon as the slot is free.
/// `update` surfaces it as soon as the slot is free. No-op when nothing
/// is pending: once the autosave OPFS directory merely exists (even with
/// no entries), queueing unconditionally would show an empty
/// "Recover Drawing" modal on every boot.
#[cfg(target_arch = "wasm32")]
pub(super) fn queue_autosave_restore_prompt(&mut self) {
if self.web_autosave_pending.is_empty() {
return;
}
if !self
.pending_startup_modals
.contains(&ModalKind::AutosaveRestore)
{
self.pending_startup_modals.push_back(ModalKind::AutosaveRestore);
self.pending_startup_modals
.push_back(ModalKind::AutosaveRestore);
}
self.show_next_startup_modal();
}
@@ -62,7 +69,8 @@ impl OpenCADStudio {
};
match &self.gpu_status {
GpuStatus::Software(adapter) => {
self.command_line.push_warning(&software_rasterizer_warning(adapter));
self.command_line
.push_warning(&software_rasterizer_warning(adapter));
}
GpuStatus::NoRenderer => {
crate::scene::pipeline::report_gpu_line(
@@ -141,9 +149,15 @@ mod tests {
// The name carries parentheses and commas of its own; the localized
// template must still place it whole. The loader follows the system
// locale here, so the assertions stay language-neutral.
assert!(warning.contains("(llvmpipe (LLVM 20.1.8, 256 bits))"), "{warning}");
assert!(
warning.contains("(llvmpipe (LLVM 20.1.8, 256 bits))"),
"{warning}"
);
assert!(warning.contains("GPU"), "{warning}");
assert!(!warning.contains("{adapter}") && !warning.contains("__ocs_"), "{warning}");
assert!(
!warning.contains("{adapter}") && !warning.contains("__ocs_"),
"{warning}"
);
// Every platform has a hint, and it is a sentence, not a missing key.
let hint = gpu_platform_hint();
assert!(hint.len() > 20 && !hint.contains("hint-"), "{hint}");