Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webworkflow warn before leaving page during upload #9625

Merged

Conversation

FoamyGuy
Copy link
Collaborator

@FoamyGuy FoamyGuy commented Sep 14, 2024

resolves: #9606

There turned out to be two different cases to handle for this:

  1. When the user attempts to navigate to a different page by clicking a link to a file, or refreshing the page
  2. When the user clicks a directory which is a link containing a hash value instead of going to a different page which does not trigger the beforeunload event

For 1 the solution of adding the event listener for beforeunload event and then preventing the default behavior causes the alert to the shown to the user confirming whether they want to leave. As far as I understand it, it's not longer possible to customize the message in that confirmation it will always be a generic message, in the past it was possible, but not in modern browsers.

For 2 since the page doesn't technically change it doesn't trigger the event. I tried for a bit to dispatch the beforeunload event "manually" but it wasn't working. In the end I realized that we could make the upload succeed instead of fail by storing the value of current_path into a local variable and using it throughout the rest of upload() rather than getting the value from the possibly changed by user action current_path variable. With this change when the user navigates to a new directory the upload just continues working and the remaining files succeed to upload, so there is no need to warn the user about leaving the page since technically the aren't, and now the remaining uploads can succeed.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!

@tannewt tannewt merged commit 015a5cf into adafruit:main Sep 16, 2024
222 checks passed
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.

Web workflow: warn about navigating away from page when an operation is in process
2 participants