Repository navigation
Block List: Render the ancestors of the selected block synchronously - #87910
Draft
draganescu wants to merge 5 commits into
Draft
draganescu wants to merge 5 commits into
draganescu wants to merge 5 commits into
Conversation
A block that is neither visible nor selected renders in async mode, and catches up with store changes only when the browser is idle. Until block visibility is first reported, or when a container is out of view, that includes a container holding the caret, such as a Template Part. Such a container syncs its controlled inner blocks with an entity, and `useBlockSync` resets the inner blocks only when the entity's blocks change between two of its renders. When the container has not rendered the edits it sent out, an undo that brings the entity back to what it last rendered goes unnoticed: the typing stays on the canvas, and the next undo reverts the previous level instead. Treat the ancestors of the selected block like the selected block, so they render each change synchronously. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🤖 PR meta 🤖📦 Bundle sizeSize Change: +36 B (0%) Total Size: 8.86 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. allows widgets to be moved between widget areas using the dropdown in the block toolbar in should undo without broken temporary state in
|
…ncestor-async-render # Conflicts: # packages/block-editor/CHANGELOG.md # test/e2e/specs/site-editor/undo.spec.js
…ncestor-async-render # Conflicts: # packages/block-editor/CHANGELOG.md
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Renders the ancestors of the selected block synchronously, like the selected block itself. This fixes an undo that a Template Part (or any other inner block controller) misses when it holds the caret.
Found while working on #87861, and independent of it: it reproduces with trunk's code.
Why?
With two Template Parts on different entities, type in the first, click into the second and type there, then undo right away. The first undo does nothing on the canvas, the second reverts the first part's typing, and the second part's typing is never reverted.
The undo history is not at fault: core-data records one level per part, and the first undo does clear the second part's edits. The canvas just never shows it:
useBlockSyncresets a controller's inner blocks only when the entity's blocks change between two of its renders. When the Template Part has not yet rendered the edits it sent out, its last render still holds the blocks parsed from the saved content. The undo brings the entity back to exactly that array, so the effect sees no change, and the typed text stays on the canvas.How?
BlockListItemsalready keeps the selected block out of async mode. It now does the same for the selected block's ancestors, which are the blocks that hold the selection. That is a handful of blocks at most, so the extra synchronous rendering is small.Testing Instructions
The new e2e test,
undo across containers of different entities, intest/e2e/specs/site-editor/undo.spec.js, types in two Template Parts on different entities and undoes them in order. It pins the race: it marks the second part as off the canvas viewport and holds the browser's idle callbacks while typing and undoing. It fails on trunk every time (6/6 runs) and passes with the fix (12/12).To try it by hand: in the site editor, add two Template Parts on different slugs to a template, type in the first, click into the second and type, then press Ctrl+Z (Cmd+Z) right away, before the parts have been on screen for half a second. Each undo should revert the typing in the opposite order.
There is no core-data or undo-manager unit test, since neither changes.
site-editor/template-part.spec.js› "doesn't throw a block error when clicking on a link" also fails locally on trunk: the test types the URL before the link input has focus. That is unrelated to this change.🤖 Generated with Claude Code