Block Editor: Partition attributes updates to avoid conflating meta and blocks attributes #15781
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.
Fixes #15739
This pull request seeks to resolve an issue where setting a new meta attribute value in a block can wrongfully displace the text caret selection.
Implementation Notes:
I consider this to be an incomplete but likely sufficient resolution to #15739. The issue occurs because a render of the block's
edit
occurs synchronously as a result ofupdateBlockAttributes
. At this point in time the meta attributes have not yet updated, so the old value is used (more at #15739 (comment)). Arguably, it is not correct (or at least ineffective) to be callingupdateBlockAttributes
with new meta values, since the selector to generate a block's attributes will always ignore these (source). To that point, the changes here will avoid callingupdateBlockAttributes
with meta value updates, and avoid calling it altogether if the only attributes updates are meta value updates. The solution works becauseupdateBlockAttributes
is avoided, and thus the problematic intermediate render does not occur.It is technically incomplete in that if a block were to call
setAttributes
with a mix of block attributes and meta attributes, a similar issue may occur. It is quite unlikely that a block would be implemented this way.In any case, I'd like to see some improvements to this sort of "external" sourcing, which would be a larger task than I propose to resolve here. I will aim to submit a formal proposal for how it might work, informed on #15739 and previous issues #4989 and #2759. An inline code comment has been added to reflect this future work.
Testing Instructions:
An existing end-to-end test case has been adapted to reveal the failure from
master
resolved here. Verify that it passes:Repeat Steps to Reproduce from #15739