-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Investigate content loss issues after connection loss/long period of time. #23781
Comments
What I managed to reproduce:
|
The autosave worked and the content is present in Post 375 is not available for me from wp-admin, but If I manually navigate to Clicking restore brings my post back: It seems like sessionStorage autosave should take |
cc @mcsf Good debugging, thanks @adamziel It does seem like a single auto-draft local save is the way to go regardless of the id. That said, I'm not sure if it's the only issue because unless I'm mistaken the "auto-save" triggers after a minute which means it's unlikely that the long post is still an auto-draft when the error happens. |
@youknowriad I kept digging and it also seems like the gutenberg/packages/editor/src/components/autosave-monitor/index.js Lines 46 to 66 in 90920ac
If I'm constantly typing, this fragment will kick in every now and then and reschedule the autosave +1 minute each time it runs. I also noticed it tends to be non-deterministic: there are times where I keep typing and the initial autosave kicks in after the first minute, and there are times where I keep typing and no autosave would kick in for 10 or more minutes. I noticed the debounce mode was added in this PR by @aduth and @mcsf: Is there any specific reason we need that debounce? I can't think of a use case where I'd like to delay the autosave indefinitely as long as I keep typing - quite the opposite, I'd like it to preserve as much of my typing as possible. I would get rid of it and just let it run every |
@adamziel I think at the time the debounce was added, the threshold was 10 seconds and not one minute and running auto-saves each 10 seconds is too much and it can lead to a high number of revisions which is bad for WP mysql performance I think. One option could be to have two timeouts, a debounced one (1 minute) and non-debounced one (like 10mn or so). |
It would also be good to display the "you are offline" notice as soon as either an autosave OR a heartbeat fails, currently it only shows in response to an autosave failure. |
@youknowriad What is the approach to the post history? Is it supposed to be immutable? I wonder if it would make sense to have a non-debounced 1-minute autosave that would create a new revision once every 10 runs and amend the last autosaved revision the other 9 times. |
Great debugging, @adamziel!
I'm speaking from memory and intuition, but I believe that traditionally consecutive autosaves are squashed together, while explicit user-triggered saves always create a new revision. So a flow of
will result in the revision history:
This might work. We should also look to make sure that the debounce fuse is good, i.e. should we shorten the idle time required to force an autosave? Would it help to consider the first (server-side) autosave more important than the following ones? The first autosave is crucial to obtain a reliable post ID with which to save/restore saves. So maybe we aggressively autosave a draft after one minute even if the editor is not idle. From that point, we know that we'll have sessionStorage autosaves at the very least. WDYT? |
#23928 would solve the sessionStorage issue for posts without a "reliable" post ID.
In that case, what's the advantage of debounced autosave over the "always run every 60 seconds" model? It seems like the number of revisions would be pretty reasonable in both cases. |
Yes, I agree. The poor answer is that the debouncing mechanism was already around before I touched Autosave. I'm tempted to say that there's currently no good reason to keep it that way, but of course I may be missing some history. Ultimately, I think it's worth reimplementing.
I think it's a fine start, but it's worth pointing out that it breaks down as soon as a user has two new drafts sitting side by side. So we're left with a couple of options:
|
Apart from the improvements to the logic, this seems like a case of poor UI where we could just surface any local-drafts whenever you start a new post, with the ability to discard them. This would mean that even if the connection between the IDs gets lost, a user would still be able to browse local copies and resurrect a text. |
This could use some design input so I created a new issue here #23955 |
Early progress on AutosaveMonitor refactor: #23962 |
Documentation for the AutosaveMonitor proposed in #26663 |
Closing this one since #23955 is a separate issue and I haven't seen any more reports of the problem described here. |
I've had an interaction with a Gutenberg user that experienced content loss while using the editor. Here are the potential steps to reproduce the issue.
At this point, the content loss happens. It's not really clear what caused it. The notice might have been dismissed, switching to writing other posts/tabs could be a factor too.
Expected Result
The text was updated successfully, but these errors were encountered: