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
Merely selecting a block after load creates undo level #14766
The action that grabs my attention is RESET_EDITOR_BLOCKS. Why are blocks being reset after block selection? The user didn't do anything that should trigger a reset?
I'd need to spend some time investigating to understand, but on hunch I think it's related to one of either reusable blocks triggering RECEIVE_BLOCKS, or as part of the refactor of a separate block editor module and how it treats "persistent" changes.
I seem to be observing that that this "dirties" the post as well, which was intended to be explicitly not the case with the implementation of #13088 . If confirmed, I'd suggest it be prioritized for a fix to be included with the WordPress 5.2 release. As a regression, it should be reasonable to expect and to implement a test as part of the change-detection.test.js suite.
There may be separate issues here between how the RESET_EDITOR_BLOCKS impacts undo history and how it impacts change detection.
For the original issue describing undo history, this may in-fact be the expected behavior, or at least there's a specific condition which forces that an undo history entry be created when history is currently empty, even if the action (RESET_EDITOR_BLOCKS) wouldn't otherwise create one.
...specifically the ! past.length condition, introduced with #4956, including some discussion at #4956 (comment) .
As an action item, I might propose to consider whether the ! past.length condition could be removed or, at the very least, updated to force the next action to behave as to merge ("overwrite") state. This latter approach doesn't resolve the issue that if, immediately after selecting the block, the user were to press Undo, the RESET_EDITOR_BLOCKS action would be inadvertently undone.
Looking at the implementation prior to changes in #13088, we seemed to include at least a few ignoreTypes: [...] It's not immediately clear to me why these were dropped
I will plan to explore a solution here, specifically seeking to restore the removed ignoreTypes.
One possible action which can incidentally serve as a solution: Rather than trigger to fetch reusable blocks immediately upon block selection, the fetch should only occur after some initial typing (i.e. when the autocomplete results are presented). This would help avoid the scenario where the fetch results are the first action dispatched to the editor store.
Looking at the implementation prior to changes in #13088, we seemed to include at least a few ignoreTypes: [...] It's not immediately clear to me why these were dropped
I will plan to explore a solution here, specifically seeking to restore the removed ignoreTypes.
Spending more time looking at this, I understand now why ignoreTypes is no longer applied for this action type, since from the editor state, REPLACE_EDITOR_BLOCKS is the sole way it tracks blocks and changes in this value are necessarily tracked to support the unsaved changes prompt.
I'd wondered then if it would be worth tying this to the shouldCreateUndoLevel property of the action dispatched. While this is workable, it doesn't seem the appropriate solution given that the property corresponds to onInput callbacks from BlockEditorProvider, something which seems a change worth considering (a branch with this proposal can be seen at fix/reset-editor-block-change-detection).
Rather, it seems the issue is that we shouldn't expect RESET_EDITOR_BLOCKS to ever occur in editor as a result of the reusable blocks being received. The way this seems to be happening is that receiving the reusable blocks triggers a receiveBlocks action in the block-editor module, where presumably this should be treated as effectively equivalent to a "syncing incoming value" operation and not bubble back up to editor by its onChange or onInput (but it does).
While related, I've split off the problem of change detection to its own issue at #14910, which I've discovered to be affecting more flows than just the block selection (opening an inserter or editing a post containing a reusable block can also trigger the prompt).
Activity
ellatrix commentedon Apr 2, 2019
The action that grabs my attention is
RESET_EDITOR_BLOCKS. Why are blocks being reset after block selection? The user didn't do anything that should trigger a reset?aduth commentedon Apr 2, 2019
I'd need to spend some time investigating to understand, but on hunch I think it's related to one of either reusable blocks triggering
RECEIVE_BLOCKS, or as part of the refactor of a separate block editor module and how it treats "persistent" changes.gutenberg/packages/block-editor/src/store/reducer.js
Lines 178 to 240 in 495f54c
Clicking on a paragraph triggers autocomplete to do the fetch for reusable blocks so that it can populate results in the slash command.
aduth commentedon Apr 8, 2019
I seem to be observing that that this "dirties" the post as well, which was intended to be explicitly not the case with the implementation of #13088 . If confirmed, I'd suggest it be prioritized for a fix to be included with the WordPress 5.2 release. As a regression, it should be reasonable to expect and to implement a test as part of the
change-detection.test.jssuite.aduth commentedon Apr 9, 2019
There may be separate issues here between how the
RESET_EDITOR_BLOCKSimpacts undo history and how it impacts change detection.For the original issue describing undo history, this may in-fact be the expected behavior, or at least there's a specific condition which forces that an undo history entry be created when history is currently empty, even if the action (
RESET_EDITOR_BLOCKS) wouldn't otherwise create one.gutenberg/packages/editor/src/utils/with-history/index.js
Lines 122 to 129 in bb3b77a
...specifically the
! past.lengthcondition, introduced with #4956, including some discussion at #4956 (comment) .For change detection, it may be a matter of configuring
withChangeDetectionto either reset at or explicitly ignore theRESET_EDITOR_BLOCKSaction:gutenberg/packages/editor/src/store/reducer.js
Lines 144 to 148 in bb3b77a
Looking at the implementation prior to changes in #13088, we seemed to include at least a few
ignoreTypes:gutenberg/packages/editor/src/store/reducer.js
Lines 411 to 416 in 4be0a36
It's not immediately clear to me why these were dropped (cc @youknowriad ).
aduth commentedon Apr 9, 2019
As an action item, I might propose to consider whether the
! past.lengthcondition could be removed or, at the very least, updated to force the next action to behave as to merge ("overwrite") state. This latter approach doesn't resolve the issue that if, immediately after selecting the block, the user were to press Undo, theRESET_EDITOR_BLOCKSaction would be inadvertently undone.I will plan to explore a solution here, specifically seeking to restore the removed
ignoreTypes.aduth commentedon Apr 9, 2019
One possible action which can incidentally serve as a solution: Rather than trigger to fetch reusable blocks immediately upon block selection, the fetch should only occur after some initial typing (i.e. when the autocomplete results are presented). This would help avoid the scenario where the fetch results are the first action dispatched to the editor store.
aduth commentedon Apr 10, 2019
Spending more time looking at this, I understand now why
ignoreTypesis no longer applied for this action type, since from the editor state,REPLACE_EDITOR_BLOCKSis the sole way it tracks blocks and changes in this value are necessarily tracked to support the unsaved changes prompt.I'd wondered then if it would be worth tying this to the
shouldCreateUndoLevelproperty of the action dispatched. While this is workable, it doesn't seem the appropriate solution given that the property corresponds toonInputcallbacks fromBlockEditorProvider, something which seems a change worth considering (a branch with this proposal can be seen atfix/reset-editor-block-change-detection).Rather, it seems the issue is that we shouldn't expect
RESET_EDITOR_BLOCKSto ever occur ineditoras a result of the reusable blocks being received. The way this seems to be happening is that receiving the reusable blocks triggers areceiveBlocksaction in theblock-editormodule, where presumably this should be treated as effectively equivalent to a "syncing incoming value" operation and not bubble back up to editor by itsonChangeoronInput(but it does).aduth commentedon Apr 10, 2019
While related, I've split off the problem of change detection to its own issue at #14910, which I've discovered to be affecting more flows than just the block selection (opening an inserter or editing a post containing a reusable block can also trigger the prompt).
aduth commentedon Apr 10, 2019
One of #14915 and #14916 should resolve this; the latter being the more "durable" solution.