You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undo: typing something after fresh post load cannot be undone #14950
I reproduced in master and also in Gutenberg 5.4.0 , but it appears as though it had been working correctly in WordPress 5.1.x .
From some initial debugging, it appears related to the block editor module in #13088, specifically around how it keeps the blocks value in sync between the two stores editor and block-editor. When pressing Undo, the state is updated to the expected values in editor store, but it's never synced back to block-editor.
In testing, when pressing Undo it appears to get stuck in the first of the condition steps of:
The new blocks value is never reflected in the block editor (resetBlocks is not called)
this.isSyncingOutcomingValue is being unset later than we expect
My expectation is that it should be unset immediately after calling onChange or onInput, not after the multi-second delay it took me before pressing the Undo button. This implies that it's waiting until some next state change before taking effect.
The issue also occurs only if multiple inputs occur within the paragraph, not just a single keypress, which would seem to indicate it could be related to undo history state merging.
I further suspect it is related to the delayed explicit creation of an undo level from RichText, where this is considered in addition to an actual change in blocks value when syncing the value from block editor.
// This happens when a previous input is explicitely marked as persistent.
(newIsPersistent&&!isPersistent)
){
blocks=newBlocks;
isPersistent=newIsPersistent;
this.isSyncingOutcomingValue=true;
if(isPersistent){
onChange(blocks);
}else{
onInput(blocks);
}
}
Since this.isSyncingOutcomingValue could potentially be set without the blocks value actually changing, it means that the logic for unsetting it in componentDidUpdate will likely not be run immediately since there is no change in props value.
A simple solution here may be to only set this.isSyncingOutcomingValue = true; if the blocks value changes, since the purpose of the value is in avoiding to resetBlocks when it occurs as a result of a change from the block editor.
Activity
ellatrix commentedon Apr 12, 2019
Not sure if this is a regression, but I'm pretty sure this worked correctly before.Looks like it is.aduth commentedon Apr 12, 2019
I reproduced in
masterand also in Gutenberg 5.4.0 , but it appears as though it had been working correctly in WordPress 5.1.x .From some initial debugging, it appears related to the block editor module in #13088, specifically around how it keeps the blocks value in sync between the two stores
editorandblock-editor. When pressing Undo, the state is updated to the expected values ineditorstore, but it's never synced back toblock-editor.In testing, when pressing Undo it appears to get stuck in the first of the condition steps of:
gutenberg/packages/block-editor/src/components/provider/index.js
Lines 38 to 43 in 0d26bba
Meaning:
resetBlocksis not called)this.isSyncingOutcomingValueis being unset later than we expectonChangeoronInput, not after the multi-second delay it took me before pressing the Undo button. This implies that it's waiting until some next state change before taking effect.aduth commentedon Apr 12, 2019
The issue also occurs only if multiple inputs occur within the paragraph, not just a single keypress, which would seem to indicate it could be related to undo history state merging.
aduth commentedon Apr 12, 2019
I further suspect it is related to the delayed explicit creation of an undo level from RichText, where this is considered in addition to an actual change in blocks value when syncing the value from block editor.
gutenberg/packages/block-editor/src/components/provider/index.js
Lines 97 to 111 in 0d26bba
Since
this.isSyncingOutcomingValuecould potentially be set without the blocks value actually changing, it means that the logic for unsetting it incomponentDidUpdatewill likely not be run immediately since there is no change in props value.A simple solution here may be to only set
this.isSyncingOutcomingValue = true;if the blocks value changes, since the purpose of the value is in avoiding toresetBlockswhen it occurs as a result of a change from the block editor.I'll give it a try.