feat(fileshare): warn before navigating away mid-upload (#116)#121
Merged
Conversation
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.
rubenhensen
approved these changes
Apr 25, 2026
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.