Skip to content

feat(fileshare): warn before navigating away mid-upload (#116)#121

Merged
rubenhensen merged 1 commit into
mainfrom
feat/upload-beforeunload-warning
Apr 25, 2026
Merged

feat(fileshare): warn before navigating away mid-upload (#116)#121
rubenhensen merged 1 commit into
mainfrom
feat/upload-beforeunload-warning

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #116. While an upload/encryption is in progress, any navigation (link click, tab close, back button) currently aborts silently — Cryptify does not support resume (tracked separately as #117), so all uploaded bytes are lost. Add the browser's standard `beforeunload` confirmation dialog while `EncryptionState.Encrypting` is active so the user gets a chance to stay.

Implementation

One `$effect` on `src/routes/(app)/fileshare/+page.svelte`. The handler is registered only while in the `Encrypting` state and torn down as soon as the state transitions to Done / Error / back to FileSelection — so users do not see the leave-page prompt on normal navigation.

Modern browsers ignore the message string returned from `beforeunload` and display their own wording ("Leave site? Changes you made may not be saved."), which is the expected behaviour — we're just telling the browser to show its prompt.

Scope note

The issue also lists the "nice to have" options of keeping uploads alive via a Web Worker / service worker and showing a global progress indicator. Both are substantially larger (involving the upload pipeline and a shared store across routes) and deliberately not in this PR — this is the minimum-viable warning path.

#117 (no retry on chunk 404) is a related upload-robustness issue but orthogonal — that's a pg-js concern, not UI.

Verification

  • `npm run check` → 0 errors / 0 warnings (335 files)
  • `npm run build` → green, static site built
  • Hooks into Svelte 5's `$effect` cleanup so the listener is removed when the state transitions away from `Encrypting` or the page unmounts.

Did not run Playwright — the suite doesn't currently exercise the leave-page dialog and browsers gate `beforeunload` on a user gesture, so a headless assert would be flaky. Sanity-checked by reading the effect in context.

Reviewer quickstart

```
git fetch origin && git checkout feat/upload-beforeunload-warning && npm install && npm run dev
```

Then open /fileshare, start an upload, try closing the tab — you should get a native browser confirmation. Finishing (or cancelling) the upload clears the handler so subsequent navigation is silent again.

Closes #116. Refs #117.

Closes #116. Cryptify does not yet support upload resume (see #117), so
navigating away during encryption/upload silently discards all progress.
Attach a beforeunload listener only while encryptionState is Encrypting
so the user gets the browser's built-in leave-page confirmation; detach
as soon as the flow transitions to Done / Error / back to FileSelection.
@dobby-coder dobby-coder Bot requested a review from rubenhensen April 24, 2026 22:17
@rubenhensen rubenhensen marked this pull request as ready for review April 25, 2026 11:45
@rubenhensen rubenhensen merged commit 2c07b8f into main Apr 25, 2026
6 checks passed
@rubenhensen rubenhensen deleted the feat/upload-beforeunload-warning branch April 25, 2026 11:45
@dobby-coder

dobby-coder Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

Dobby sees Master rubenhensen's approval! Dobby is most pleased — but Dobby notices the pull request has already been merged into main. There is nothing more for Dobby to do here. Dobby thanks Master for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warn users that navigating away cancels an in-progress upload

1 participant