[stable30] feat(session): Send save request via sendBeacon at beforeunload#7061
Merged
[stable30] feat(session): Send save request via sendBeacon at beforeunload#7061
sendBeacon at beforeunload#7061Conversation
9bc4d17 to
06fa356
Compare
mejo-
approved these changes
Apr 2, 2025
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## stable30 #7061 +/- ##
=========================================
Coverage 53.68% 53.68%
=========================================
Files 116 116
Lines 2578 2578
Branches 527 527
=========================================
Hits 1384 1384
Misses 1066 1066
Partials 128 128 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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>
06fa356 to
c6990dc
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.
Backport of #6798