feat(session): Send save request via sendBeacon at beforeunload#6798
Merged
feat(session): Send save request via sendBeacon at beforeunload#6798
sendBeacon at beforeunload#6798Conversation
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
Collaborator
|
I will try it out |
215b87b to
5a9e80e
Compare
Member
Author
|
A good way to test this is to set a debugger breakpoint (e.g. in |
bcb0bc3 to
d7482df
Compare
Member
Author
|
/backport to stable31 |
Member
Author
|
/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 <jonas@freesources.org>
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 <jonas@freesources.org>
d7482df to
1df2abd
Compare
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
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)