-
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
Support disabling autosave for native Unsupported Block Editor #35639
Conversation
Size Change: +19 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
Previously, there was no way to disable the autosave timer created within `AutosaveMonitor`'s `componentDidMount` hook. This resulted in unexpected remote drafts to be saved from within the native editor's Unsupported Block Editor (UBE) after the timer's 60 seconds elapsed. The UBE loads the web-based editor within a web view and leverages `autosaveInterval` to prevent autosave creating remote drafts. This change enables clearing the initial autosave timer by modifying `interval` via `autosaveInterval`. Now, when the `interval` changes the previous timer is cleared and a new timer is created with the new `interval`.
597f84f
to
76486d0
Compare
👋 Hi @dcalhoun, I want to make sure I understand how this change resolves wordpress-mobile/gutenberg-mobile#4130. I see that the UBE sets Is it your understanding that previous to #23962, setting Either way, should we look at adding an editor setting to disable auto-save entirely (if the goal is to disable auto-save)? |
My understanding is that before #23962 the initial timer was reset by modifying
We could. With UBE, we utilize the One might argue that is a new boolean is more explicit and clear. However, I question if its clarity is worth the value of its addition and maintenance. WDYT? Additionally, I will point out there is already a |
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.
My understanding is that before #23962 the initial timer was reset by modifying
autosaveInterval
. Prior to #23962, a change in the component's props resulted in a conditional reset of the timer. After #23962, a change in the component's props only ever sets an internal reference. So, there is no opportunity to clear the initial timer now set on mount.
Thanks for explaining that, @dcalhoun, makes sense.
We could. With UBE, we utilize the
window.wp
global to mutate the store. So, anything we mutate —autosaveInterval
orfutureBooleanPropToDisableAutosaveEntirely
— will occur after the initial mount ofAutosaveMonitor
. I.e. it will not change the approach or need to clear the initial timer, it is merely a difference between an explicit boolean or setting an "unreachable" interval for autosave. I do not have a strong opinion on whether a boolean is necessary.One might argue that is a new boolean is more explicit and clear. However, I question if its clarity is worth the value of its addition and maintenance. WDYT?
Good point, if the settings are read like that, it sounds like there's no way to avoid the timer being created at least once. I don't know of any way to access these settings from the UBE without going through window.wp
.
Additionally, I will point out there is already a
disableIntervalChecks
prop, but it is a local component prop, not a value in the store. It is used by the native editor. However, the UBE loads the web editor.
My reading of this prop's documentation here was that setting it to true
causes an autosave to be triggered every time there's a change to the editor contents (effectively removing the delay set by the interval). So I didn't see how it could help here.
I tested this PR using the instructions found above and everything seems to be working correctly. Without the plugin Gutenberg activated, unwanted drafts are created. With the plugin, I no longer see unwanted draft posts being created. I also checked the web editor and it's still working as expected.
Thanks for wrangling this, @dcalhoun!
Description
Relates to wordpress-mobile/gutenberg-mobile#4130.
Previously, there was no way to disable the autosave timer created within
AutosaveMonitor
'scomponentDidMount
hook, which was added in #23962. This resulted in unexpected remote drafts to be saved from within the native editor's Unsupported Block Editor (UBE) after the timer's 60 seconds elapsed. The UBE loads the web-based editor within a web view and leveragesautosaveInterval
to prevent autosave creating remote drafts.This change enables clearing the initial autosave timer by modifying
interval
viaautosaveInterval
. Now, when theinterval
changes the previous timer is cleared and a new timer is created with the newinterval
.How has this been tested?
Unexpected Drafts Not Created
npm run build:plugin-zip
to generate an archive of Gutenberg.?
button on the unsupported block.Intentional Changes Persisted
Complete steps 1-7 above, then...
Screenshots
n/a
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).