Repository navigation
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
f15645b to
fe50598
Compare
| const parents = blockClientId ? getBlockParents( blockClientId ) : []; | ||
|
|
||
| for ( let i = parents.length - 1; i >= 0; i-- ) { | ||
| if ( areInnerBlocksControlled( parents[ i ] ) ) { |
There was a problem hiding this comment.
Answers the question: which controlled block area (if any) currently owns this selected block?
|
Size Change: +104 B (0%) Total Size: 7.51 MB 📦 View Changed
|
| areInnerBlocksControlled | ||
| ); | ||
|
|
||
| if ( selectedControllerId && selectedControllerId !== clientId ) { |
There was a problem hiding this comment.
If selectedControllerId is undefined continue restore selection as before.
I'm not quite sure yet if this is the right way, I'm not familiar with this function. The logic I'm following is basically, if the user is actively selecting/typing inside another controlled area we should keep that selection.
| ); | ||
|
|
||
| if ( selectedControllerId && selectedControllerId !== clientId ) { | ||
| return; |
There was a problem hiding this comment.
Before this change, restoreSelection() did this:
- Read the saved selection from
SelectionContext. - Check whether the saved selection’s client ID “belongs” to this
useBlockSynccontroller. - If yes, convert the saved external client ID into this controller’s internal cloned client ID.
- Call
resetSelection()so the block editor selection moves there.
That works when there is only one rendered copy of a controlled block list.
The problem is step 2. For controlled inner blocks, "belongs to this controller" means:
idMappingRef.current.externalToInternal.has( startClientId )If two Post Content blocks render the same post entity, both have clone maps for the same external paragraph ID. So both can say "yes, this selection belongs to me".
Before the guard, whichever controller restored later could call resetSelection() and move (jump) focus into its own cloned paragraph.
After the guard, a controller still restores selection when appropriate, but it first checks whether the current live selection is already inside another controlled area. If it is, this controller does not call resetSelection().
|
I think this fixes #79096 as well. BeforeKapture.2026-06-23.at.16.21.20.mp4AfterKapture.2026-06-23.at.16.21.59.mp4 |
|
Flaky tests detected in 3ab6014. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28007338808
|
fe50598 to
3ab6014
Compare
|
Closing in favour of #79097 |
Fixes #79096. Two blocks can render the same entity — two Navigation blocks using one menu, a Post Content block at a template root and another inside a template part. Each is an inner block controller holding private clones, but both clone the same blocks, so both build the same external-to-internal ID mapping and both recognise the entity's selection as their own. An edit in one instance therefore reaches the other as an incoming entity change. That controller re-clones and calls restoreSelection, which converts the external ID to its own copy and dispatches resetSelection. The canvas scrolled to the duplicate and the caret left the block being typed in, reliably enough to reorder characters. Guard the restoreSelection call instead: when the selection already sits inside a different inner block controller, this sync is a consequence of an edit made there, so leave it alone. The controller that made the edit takes the outgoing branch and never reaches this code, so a selection held by another controller is always one that has been dealt with. A selection held by the root block list belongs to no controller and still restores as before, which is what keeps entity navigation and undo working. The guard sits at the call site rather than inside restoreSelection: the question is about the sync that just happened, not about the selection object, and restoreSelection keeps its existing contract. This reuses getBlockParents and areInnerBlocksControlled, already selected in this hook, so there is no new store state, no new action or selector, and nothing persisted into entity data or collaborative state. Revives the approach in #79422 by @ramonjd, which asked the same question with the same selectors and was closed by its author in favour of #79097. Two differences: the check moved to the call site, and the WeakMap remembering the last controller to hold the selection is left out. Also removes two tests added with the failing coverage. They asserted that undo returns the caret to the block whose edit was undone. Trunk does not do that for any nested entity, with or without duplicates: a controller records its selection against its own entity, but the only consumer of a recorded selection reads the root record. That is a separate, pre-existing gap and out of scope here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RtcwXT84eF6zLdQXK9e1W
What?
Noticed while testing #79191 (review)
Related to #79096 (maybe)
This prevents a controlled inner block controller from restoring a shared post entity selection when the current editor selection already belongs to another controlled block list.
It also adds e2e regression coverage for Show template mode with one Post Content block at the template root and another nested inside a Template Part.
Why?
When the same post content is rendered in more than one editable Post Content instance, each instance has different cloned block client IDs, but they map back to the same external post block IDs. That allowed an inactive Post Content instance to treat the saved entity selection as its own and move focus to its cloned block.
Testing Instructions
Screenshots
Before
Kapture.2026-06-23.at.14.35.15.mp4
After
Kapture.2026-06-23.at.15.41.15.mp4