-
Notifications
You must be signed in to change notification settings - Fork 109
feat(session): Send save request via sendBeacon at beforeunload
#6798
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6798 +/- ##
==========================================
- Coverage 58.79% 58.76% -0.03%
==========================================
Files 477 477
Lines 35855 35885 +30
Branches 988 988
==========================================
+ Hits 21080 21089 +9
- Misses 14670 14691 +21
Partials 105 105 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
009a095 to
2fa0402
Compare
2fa0402 to
215b87b
Compare
|
I will try it out |
215b87b to
5a9e80e
Compare
|
A good way to test this is to set a debugger breakpoint (e.g. in |
bcb0bc3 to
d7482df
Compare
|
/backport to stable31 |
|
/backport to stable30 |
It used to check if the last saved version of the document is older than the current version. But `document.currentVersion` no longer exists in the backend response, so this didn't work since quite some time. Signed-off-by: Jonas <[email protected]>
This will send a final save request on unsaved changes via the browsers native `navigator.sendBeacon()` function when navigating away from the website or the tab/browser is closed. Fixes: #6606 Implementation details: * While `beforeunload` event is less reliable than `visibilitychange` according to different sources on the internet, tests in Firefox on Linux desktop revealed that `visibilitychange` event doesn't fire when opening a new website in the same tab. `beforeunload` on the other hand reliably worked when switching web page and closing tab/browser. * We add and remove the `beforeunload` event with every `dirty` state change because according to MDN documentation websites with a registered `beforeunload` event don't benefit from bfcache optimization. See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event Signed-off-by: Jonas <[email protected]>
d7482df to
1df2abd
Compare
max-nextcloud
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
📝 Summary
This will send a final save request on unsaved changes via the browsers native
navigator.sendBeacon()function when navigating away from the website or the tab/browser is closed.Implementation details:
beforeunloadevent is less reliable thanvisibilitychangeaccording to different sources on the internet, tests in Firefox on Linux desktop revealed thatvisibilitychangeevent doesn't fire when opening a new website in the same tab.beforeunloadon the other hand reliably worked when switching web page and closing tab/browser.beforeunloadevent with everydirtystate change because according to MDN documentation websites with a registeredbeforeunloadevent don't benefit from bfcache optimization. See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_eventFixes: #6606
🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)