Skip to content

Block Editor: Reconcile a restored selection once for the whole canvas - #87861

Open
draganescu wants to merge 46 commits into
trunkfrom
try/reconcile-selection-once
Open

draganescu wants to merge 46 commits into
trunkfrom
try/reconcile-selection-once

Conversation

@draganescu

@draganescu draganescu commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What?

Follow-up to #82706, for #79096.

#82706 stopped blocks that show the same saved blocks, such as two Navigation blocks on one menu or two Post Content blocks, from taking the caret from each other while you type. This PR fixes where the caret goes on undo and redo. An undo or a redo now brings the caret back to the block it changed, in the copy where the edit was made, even when the caret has since moved to another copy or to another inner block controller, such as a second Template Part or the Post Content of another post. It does this by replacing #82706's guard by block type with one place that decides the selection for the whole canvas, with no public API and no new store state.

Why?

Each inner block controller keeps private clones of the blocks it shows and restores the recorded selection on its own. Its only test is whether the recorded block is in its own mapping, which is true for every copy of the same entity, so on its own the last copy to sync takes the caret. #82706 added a guard: a controller skips the restore while the caret is in another controller of the same block type. That guard leaves three gaps:

  • Undo leaves the caret where it is. Type in one Navigation block, click into the other, and undo: the text reverts, but the caret stays in the block you clicked instead of going back to the edit, as undo does everywhere else.
  • Different entities count as copies. Two Navigation blocks on different menus, or the Post Content of another post, are of the same block type, so an undo with the caret in one of them leaves it there.
  • A nested controller's undo never brings the caret back. An undo of a Template Part's own entity does not change the selection recorded on the root record, which is the only one the canvas read. This predates Block Editor: Stop duplicate controllers from taking the selection #82706 and was pinned there as a test.fixme.

How?

Where the selection goes is a question about the whole canvas, so the root provider now answers it once. The in-place update of a controller's clones, the undo reducer rule and the metadata fix from #82706 stay as they are. Its guard by block type is replaced by the following.

  • One reconciler per canvas. The root BlockEditorProvider creates a private SelectionReconciler in a ref, outside the block-editor store, because any change to the blocks state would end a typing run. Inner controllers no longer restore the selection themselves. Each inner useBlockSync only keeps the reconciler informed: it registers its ID mapping while mounted, asks for a reconciliation after it takes blocks from outside, and notes when a re-clone replaced the clones the selection was on.
  • It decides once, on a settled canvas. The reconciler runs in a microtask, after every controller syncing in that pass has synced, and calls resetSelection at most once. The order the copies sync in no longer matters.
  • One pure function, pickSelectionTarget. Given the recorded selection, the store's selection, the controllers in canvas order and which controller holds the selected block, it names the one controller that should show the recorded selection, the root block list, nobody (already in place), or that no block on the canvas shows it. The copy holding the caret keeps it when it can show the recorded block; otherwise the first copy on the canvas that can show it takes it.
  • The recorded selection is applied only through a controller that just synced from outside, as after an undo. Typing in one Navigation copy does not update the root's recorded selection, so without this rule a record that has fallen behind the caret would pull it back. Otherwise the selection stays where it is, moved onto the new clones if its controller replaced the ones it was on.
  • Undo and redo return to the edited copy. Each controller tells the reconciler where the selection was before and after every edit it sends out, keyed by the blocks value it replaced and the one it sent. An undo or a redo gives the controller one of those values back by reference, so the reconciler knows which copy made the edit and where its caret was, and that copy shows the selection again. The history is a WeakMap inside the reconciler: nothing is added to the entity, the selection record or the store. It applies only when the edited copy itself took the value back, so a copy that mirrors another copy's keystroke a render late never pulls the caret back.
  • Focus follows a selection moved into another controller. A field that has focus reports its own caret as the selection whenever its text changes, as an undo changes the text of every copy. So when the reconciler moves the selection into another controller, it blurs the focused field and passes a caret position, and the block the selection moves to takes focus.
  • One definition of ownership. A block belongs to the nearest parent whose inner blocks are controlled, or to the root block list. Restoring and reporting a selection both use it. A block created inside a controller has no clone, so its own ID is its external ID.

Compared with the closed alternatives

One behaviour change on the reporting side: ownership comes from the block tree, so a selection change inside a block just created in a copy is reported to the entity. Before, no controller reported those.

Testing Instructions

Steps 2, 4 and 5 check that #82706's fixes still hold; steps 3 and 6 show what this PR changes.

  1. In the site editor, open a template and add two Navigation blocks using the same menu, with a tall spacer between them.
  2. Type in a link label of the first block. The text appears in both blocks, the caret stays in the first, and the canvas does not scroll.
  3. Click into the same link in the second block and undo. Both labels revert, and the caret goes back to the link in the first block. Click into the second block again and redo: the caret goes back to the first block again.
  4. Select a link in the first block, move it right with the block toolbar, then undo. The selection stays in the first block throughout.
  5. Open a post with "Show template" on, in a template that shows Post Content twice. Typing in one instance keeps the caret there, and one undo removes the whole typed run.
  6. In a template with two Template Parts on different slugs, type in the first, click into the second, and undo. The text reverts and the caret goes back to the first Template Part.

Proofs run

The Trunk column was run before #82706 landed, with trunk's packages/block-editor/src built against this branch's specs, and then on this branch. P1 to P3, P11 and P14 are #82706's fixes, which trunk now has; they are kept here as regression checks. P8, P16, P17 and P18 are what this PR changes. The e2e runs used --trace=on.

ID Claim Trunk Branch
P1 Typing in one of two Navigation blocks on one menu never moves the caret into the other, and the canvas does not scroll (site-editor/navigation-selection-sync.spec.ts) Fails Passes
P2 A typed run reads in order, one undo removes it and one redo brings it back in both copies (site-editor/undo.spec.js) Fails, keystrokes lost Passes
P3 P1 for two Post Content blocks with Show template on (editor/various/post-content-focus-mode.spec.js) Fails Passes
P4 Adding a page with the Navigation block's "+" leaves the selection in that block Passes Passes, so this does not show a fix
P5, P6 Undo moves the caret within Post Content, and back from Post Title Passes Passes
P7 Undo brings the caret back from another post's Post Content (case and block from #87777) Passes Passes
P8 Type in A, click into B, undo: both revert and the caret goes back to the item in A; redo from B does the same Not run against the new expectation Passes
P9, P10 Only one controller resets the selection, the same one for every copy, with 2 and 3 copies in every sync order (unit) n/a Passes
P11 Add, remove or move an item in one copy, then undo: the selection stays in that copy, in both sync orders (unit, plus e2e for the move) e2e fails Passes
P12 The registry drops unmounted copies and follows a switched menu, and is empty after 50 mount and unmount cycles (unit) n/a Passes
P13 Both patterns.spec.js files, template-part-focus-mode.spec.js, editor/various/undo.spec.js, and the provider and reducer unit suites Passes Passes (74 e2e, 348 unit)
P14 Undoing the creation of an unsynced pattern makes its blocks editable again (from #82706) Passes Passes, so this does not show a fix
P15 No new store state or public option, and npm run docs:build leaves no diff n/a Holds
P16 Type in one Template Part, click into another, undo: the caret goes back to the first (site-editor/undo.spec.js, was test.fixme) Fails: the caret stays in the second part Passes
P17 Type in the Post Content at the template root, click into the one inside a Template Part, undo: the caret returns to the root one (test from #87845) Not run Passes
P18 Undo or redo of a value returns the selection to the copy that edited it, for a copy of the same entity and for another entity, but not when another copy only mirrors a keystroke late (unit) n/a Passes

With --repeat-each=3, the Navigation, Post Content, editor undo and site editor undo specs passed 132 of 132 runs. Unit: 360 of 360. The full set above also includes "Synced pattern › can be inserted after refresh" in editor/various/patterns.spec.js, which fails about 2 runs in 3 when run on its own: it types into the slash inserter before the new pattern is available, as #87845 also notes. No selection code is involved.

Testing Instructions for Keyboard

Repeat steps 2 to 4 with the keyboard: Tab into the link, type, use the arrow keys, and undo with Cmd/Ctrl+Z.

Out of scope

  • Typing in a second Template Part is not recorded as an undo level of its own, on trunk too, so the first undo after it does nothing and its typing is never reverted. That is a bug in the undo history, separate from the selection, and the Template Part test above only clicks into the second part.
  • Selection restore under real-time collaboration.
  • Any change to packages/block-library or packages/core-data, and any public API.

Use of AI Tools

Written with Claude Code (Claude Opus 5.5): the implementation, the tests and this description. I reviewed the changes and ran the unit and e2e proofs above.

🤖 Generated with Claude Code

jeryj and others added 30 commits December 2, 2026 23:10
Adds failing coverage for #79096 and regression guards for the behaviour
a fix must not break.

Two blocks rendering the same entity (two Navigation blocks on one menu,
two Post Content instances) each clone that entity's blocks privately but
build identical external-to-internal ID maps. In useBlockSync's
restoreSelection, ownership is decided by whether the external ID appears
in that map, which every such controller answers true to, so an edit in
one instance is followed by the other claiming the selection.

Failing (the defects):
- editing a menu item leaves the caret and selection in the edited block
- undoing a menu edit returns the caret to the block that made it
- undo moves the caret back into the Navigation block when the caret has
  moved outside it
- typing in one Post Content instance leaves the caret and selection in
  that instance

The last two are a second, separate gap: a nested controller records its
selection against its own entity, but the only consumer of a recorded
selection reads the root record, so cross-controller undo never restores
the caret.

Passing (guards for existing behaviour):
- undo restores the caret to the undone block when another block is
  selected
- selection is restored after returning from a template part

The duplicate tests record every selection entering the other instance
rather than asserting on the final selection: the steal is often
momentary, and the canvas scrolls as soon as it happens even when the
selection recovers. A final-state assertion passed 4 runs in 5.

The Navigation spec is adapted from
#79929.

Also makes Template Part Focus mode activate its theme per test; the
theme was restored after each test but only activated in beforeAll, so
any second test in the file ran against the wrong theme.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RtcwXT84eF6zLdQXK9e1W
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
…root

getBlockParents collects every ancestor up to the document root and is
memoized on state.blocks.parents, which changes on each re-clone, so the
memo never hits on this path. The answer is almost always the immediate
parent, since a menu item sits directly inside its Navigation block.

Walk up with getBlockRootClientId instead, stopping at the first
controller, and short-circuit on the controller's own mapping when the
selected block is one of its clones.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RtcwXT84eF6zLdQXK9e1W
The existing comment describes restoreSelection, so it belongs inside the
guard rather than above it. Also records why the guard is checked after
the blocks are set.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RtcwXT84eF6zLdQXK9e1W
Per review on #82706: check that an undo can still move the selection
from one block of a controlled container to another. Post Content is an
inner block controller, so two of its blocks exercise that path.

Passes identically with the guard enabled and disabled, five runs each.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RtcwXT84eF6zLdQXK9e1W
Two Template Parts pointing at the same entity are both inner block
controllers synced from one record. These pin the two behaviours that
matter when typing into one of them.

The first passes: every typed character survives, in both copies. That is
the behaviour the preceding commits on this branch fixed, and it
regresses silently, so it is worth holding down.

The second fails. One undo removes a single character rather than the
whole typed run, because each keystroke makes the *duplicate* run
setControlledBlocks() and dispatch replaceInnerBlocks. That action lands
between keystrokes and breaks the isUpdatingSameBlockAttribute merge
chain, so every character becomes its own undo level. Marking the change
not-persistent does not help: any intervening action on another block
breaks the chain regardless. restoreSelection is not involved — the
existing guard keeps it from firing during typing.

Both tests type at a human cadence on purpose. An instant
keyboard.type() outruns the re-sync and passes, so the delay is
load-bearing rather than incidental.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UTowaGipHSMef7nUQAnnJJ
Two containers rendering one entity, such as two Template Parts on the
same slug, are both inner block controllers. Typing in one edits the
entity, and the other mirrors the edit onto its own clones as a change
ignored by history. The persistence reducer still recorded that change
as the last action, so the next keystroke no longer looked like a
continuation of the run and was filed as a new undo level. Undo then
removed one character at a time.

A history-ignored change that leaves the last-updated block's entry and
attributes untouched now keeps the previous last action, so the run
continues across it. A change that does replace that block, such as the
reset after an undo, still starts a new level.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6LxkvDuGJg68a7c8KJKry
…tes change

An inner block controller rebuilt its whole subtree whenever its entity
changed: it cleared the ID mapping, cloned every block under a fresh
client ID and replaced the inner blocks. With two containers rendering
one entity, that happened on every keystroke made in the other one. Each
keystroke tore down and remounted every block and rich text in the
duplicate, briefly left it without a selection, and dispatched a block
replacement into the store between two keystrokes.

When the incoming value has the same structure as the current clones,
the same external IDs in the same order, the controller now applies the
changed attributes to the existing clones as one history-ignored update.
The mapping, the mounted components and the selection stay valid. A
structural change still takes the rebuild path.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6LxkvDuGJg68a7c8KJKry
An undo that reverts an edit in one Template Part while the caret sits in
another should bring the caret back to the reverted block, as it does at
the root of the document. It does not yet: a nested controller only
restores the selection recorded on the root record, which an undo of its
own entity never changes. The test is marked fixme to document the gap.

The duplicated-container tests now also delete saved templates when they
finish, since a leftover saved index template made their setup fail.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6LxkvDuGJg68a7c8KJKry
The nearest controlled ancestor of the selected block is its holder. The store already has an ascending parent list, so use that instead of walking the tree by hand.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UpQLN4sQKUDBA45FqsyUQY
Two fixes to the duplicate controller guard and in-place update.

The guard skipped restoring the selection whenever the nearest
controlled ancestor of the selected block was not this controller. A
controller nested inside this one, such as a synced pattern inside Post
Content, is still part of this copy, so an undo in Post Content no
longer moved the caret back while it sat in the pattern. A selection
anywhere inside this controller now counts as its own.

The in-place update compared only attributes, so a change to any other
block field never reached the clones. The Custom HTML block keeps its
markup in innerContent and edits it with updateBlock: undoing that edit
in a container left the new markup on screen, and the next edit there
wrote it back into the entity. A value whose blocks differ in any field
other than attributes and inner blocks now re-clones, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The in-place update and its tests were written in JavaScript before
useBlockSync moved to TypeScript on trunk. Give the helpers and the test
harness their types so the dev project type checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trunk now requires new end-to-end spec files to be TypeScript.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two regressions against trunk in how a controller restores the
selection after an incoming change.

The in-place update left the record of the last restored selection in
place, so an undo handing back that same selection object skipped the
restore. That happens on undo, type, undo: typing without moving the
caret first records the selection the first undo restored. Clear it
after an in-place update, as re-cloning does.

The guard took any controller above the selected block for another
copy of this entity. A Template Part holding Post Title and Post
Content then stopped an undo in Post Content from moving the caret
back while it sat on Post Title. Another copy is always a block of the
same type, so only count controllers of this controller's block type.

Also trims the changelog entry to what changes for users of the
package, and names duplicate Post Content blocks in it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two end-to-end tests for the selection restore fixed in the previous
commits, both with the page's template shown:

- With Post Title and Post Content in one Template Part, an undo in Post
  Content brings the caret back from Post Title.
- On undo, type, undo, the second undo brings the caret back to where
  the typing started.

Both fail without those fixes. Each first types a second after the
editor loads: the first typing after loading does not always get an
undo level of its own, on trunk too, which made the tests flaky.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guard counts any controller of the same block type as a copy, so two
Template Parts on different slugs count as copies of each other too.
Say so next to the guard, and in the undo test pinned as fixme, which
the guard would also block once its other cause is fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Until the canvas reports Post Content as visible, a moment after it
renders, the block reads the post asynchronously. Typing then undone
quickly is missed altogether, leaving its blocks with the typing while
the post no longer has it. Wait for that state instead of a timeout,
and undo once per typing now that no undo can go missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like the other two undo tests, this one typed before Post Content was
reported visible, so the first undo could be missed. An undo-until
loop absorbed that, but it would equally have accepted the two edits
being merged into one undo level. Wait for visibility instead, and
check that each undo reverts exactly one edit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two checks had no test that fails without them:
- a reorder of the same blocks must re-clone, or each clone stays
  mapped to the block that used to be in its place, and an edit to one
  is reported as an edit to another;
- an undo that updates the edited block in place must start a new undo
  level for the next typing, or the next undo also takes back the edit
  before it.

Also correct comments that still describe a duplicate re-cloning
between keystrokes, drop a claim that the selection guard has to run
after the blocks are set (either order restores the selection), and
name the nested-controller re-clone case for what it covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The hook ignores changes to the clones of a controller that has no
block in the store, so the check that an in-place update is not
reported back passed whatever the hook did. With a host block, it
fails when the hook stops marking the update as incoming.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three conditions had no test that fails without them:
- a copy's in-place mirror of another copy's keystroke must be ignored
  by history, or each keystroke starts an undo level of its own;
- the reducer rule must apply only to changes history ignores, or
  typing in a second block splits into one level per keystroke;
- the nested-controller selection test must take the in-place path
  when it says it does.

Also correct a reducer test comment that credited the block entry for
what its attributes catch, and reuse the Post Content text helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename hasSameFields to areBlockFieldsEqual and leavesBlocksUntouched
to areLastUpdatedBlocksUnchanged, so that each name says what it
compares, as suggested in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lection

The selection guard checked only the parents of the selected block, so
a selection on another copy's own block did not count. Adding a link to
a Navigation block can leave that Navigation block selected, and review
caught the duplicate then restoring the previous link onto its own
clone, pulling the selection into it. Count the selected block as well
as its parents.

Also say in the guard why it counts copies by block type rather than by
a registered entity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One redo must bring the whole typed run back, in both containers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts metadata

When a container updates its inner blocks in place, an undo that removes
the metadata of an unsynced pattern arrives as `metadata: undefined`. The
derived editing modes only treated a truthy `metadata` as a change, so the
pattern's blocks stayed content only until the page was reloaded. Count
`metadata` as changed whenever the update includes it.

Reported by ramonjd in review, with the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…removed

Removing an attribute can change more than the attribute. A Navigation
block whose `ref` an undo removes no longer controls its inner blocks, so
they have to come from the incoming value. The in-place update leaves the
inner blocks of a controller alone, so the block kept the menu's links,
lost its own, and then picked the menu again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One pure function that every controller on the canvas asks, so that all
copies of the same blocks get the same answer. Its tests include two
cases where every copy clones its blocks again before asking, which fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nTarget names

Controllers register their ID mappings in the selection context, and
restoreSelection asks pickSelectionTarget instead of testing only its own
mapping. Removes the guard by block type from #82706. The structural
change tests fail when the edited copy is second on the canvas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two controllers of one type on different entities, where the caret has to
go back to the one that can show the recorded block, and two copies of
one entity, where it stays in the copy the person clicked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
draganescu and others added 4 commits December 2, 2026 23:48
…lone

After a structural change each copy clones its blocks again in its own
effect, so a copy could ask pickSelectionTarget while the store's
selection still named a clone that another copy had just replaced, and
the copies disagreed on who restores the selection.

A copy's mapping now translates the clones it replaced until its next
re-clone, and maps the blocks created in it when it reports them, so the
canvas always knows which copy holds the selected block. A selection on
a replaced clone is not in place, so its holder moves it to the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings over the case and the Test Post Context Provider block from #87777.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a page with the block appender, undoes from the other block, and
moves an item and undoes the move in either block, checking that the
selection never enters the other block and the canvas does not scroll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@draganescu
draganescu requested a review from ellatrix as a code owner December 2, 2026 22:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jeryj <jeryj@git.wordpress.org>
Co-authored-by: draganescu <andraganescu@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +1.02 kB (+0.01%)

Total Size: 8.86 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 564 kB +1.02 kB (+0.18%)

f677058 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 6ec54b3 trunk % Change
timeToFirstByte 49 ms +3.06% -3.16% 49.2 ms +7.93% -1.73% -0.41%
largestContentfulPaint 76 ms +13.16% -0% 78 ms +10.26% -2.56% -2.56%
lcpMinusTtfb 28.55 ms +11.91% -5.43% 28.7 ms +29.09% -6.1% -0.52%
wpBeforeTemplate 24.42 ms +7.29% -2.05% 24.51 ms +6.85% -1.31% -0.37%
wpTemplate 20.15 ms +3.87% -2.48% 20.15 ms +7.25% -2.13% 0%
wpTotal 45.08 ms +3.33% -2.77% 45.56 ms +5.6% -2.15% -1.05%
wpMemoryUsage 7.76 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 6ec54b3 trunk % Change
timeToFirstByte 40.4 ms +2.48% -2.72% 40.2 ms +4.48% -1.62% 0.5%
largestContentfulPaint 72 ms +5.56% -0% 72 ms +2.78% -0% 0%
lcpMinusTtfb 33.05 ms +5.75% -2.72% 32.2 ms +2.48% -1.86% 2.64%
wpBeforeTemplate 21.55 ms +1.86% -1.72% 21.64 ms +2.13% -1.48% -0.42%
wpTemplate 15.37 ms +4.16% -4.16% 15.43 ms +4.08% -2.98% -0.39%
wpTotal 37.27 ms +2.52% -3.01% 36.9 ms +5.42% -1.71% 1%
wpMemoryUsage 6.47 MB +0% -0% 6.43 MB +0% -0% 0.55%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 6ec54b3 trunk % Change
mediaProcessingJpeg 398.12 ms +1.72% -1.66% 408.13 ms +0.5% -5.66% -2.45%
mediaProcessingAvif 5690.36 ms +0.46% -0.14% 5696.3 ms +0.13% -0.22% -0.1%
mediaProcessingJpegToAvif 3868.47 ms +0.42% -0.31% 3871.02 ms +0.23% -0.3% -0.07%

media-upload

Metric 6ec54b3 trunk % Change
jpegUploadProcessing 1473.46 ms +35.11% -1.04% 1475.16 ms +0.81% -0.73% -0.12%
pngUploadProcessing 249.07 ms +1.12% -3.23% 246.63 ms +0.83% -4.82% 0.99%
largeJpegUploadProcessing 1463.64 ms +0.42% -0.57% 1466.72 ms +0.42% -1.01% -0.21%
multipleImageUploadProcessing 1606.85 ms +0.75% -0.2% 1650.66 ms +0.28% -2.19% -2.65%

post-editor

Metric 6ec54b3 trunk % Change
serverResponse 477.8 ms +3.44% -9.71% 474.29 ms +1.35% -8.16% 0.74%
firstPaint 391.35 ms +10.34% -5.81% 417.43 ms +9.56% -11.13% -6.25%
domContentLoaded 814.57 ms +1.46% -2.7% 816.97 ms +1.48% -0.69% -0.29%
loaded 815.87 ms +1.43% -2.71% 818.17 ms +1.47% -0.65% -0.28%
firstContentfulPaint 453.18 ms +4.27% -3.16% 455.67 ms +2.1% -1.2% -0.55%
firstBlock 2182.14 ms +1.66% -1.25% 2191.03 ms +1.41% -0.92% -0.41%
type 17.71 ms +4.29% -11.18% 17.74 ms +8.4% -12.85% -0.17%
typeWithoutInspector 17.48 ms +4.29% -8.01% 17.81 ms +5.22% -8.76% -1.85%
typeWithTopToolbar 23.93 ms +2.93% -10.7% 22.75 ms +8.4% -10.86% 5.19%
typeContainer 8.48 ms +6.84% -8.73% 8.38 ms +4.65% -11.1% 1.19%
focus 107.46 ms +6.33% -3.9% 98.46 ms +6.96% -7.7% 9.14%
firstFocus 256.88 ms +0% -0% 267.06 ms +0% -0% -3.81%
selectAll 391.18 ms +1.2% -4.09% 380.64 ms +5.11% -0.19% 2.77%
undo 27.61 ms +9.09% -1.67% 27.93 ms +4.87% -3.58% -1.15%
listViewOpen 38.02 ms +15.81% -5.31% 39.26 ms +7.46% -7.18% -3.16%
inserterOpen 39.98 ms +5.23% -3.45% 38.36 ms +18.46% -11.84% 4.22%
inserterHover 11.53 ms +4.42% -6.94% 10.92 ms +6.41% -11.54% 5.59%
inserterSearch 8.14 ms +8.97% -1.72% 8.35 ms +14.85% -6.23% -2.51%
loadPatterns 675.19 ms +5.12% -6.28% 652.58 ms +4% -3.51% 3.46%
wpTotal 468.17 ms +3.51% -9.89% 464.52 ms +1.4% -8.28% 0.79%
wpMemoryUsage 14.86 MB +0% -0% 14.82 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 6ec54b3 trunk % Change
serverResponse 408.16 ms +1.1% -9.8% 403.95 ms +0.56% -5.46% 1.04%
firstPaint 418.45 ms +9.89% -8.82% 374.18 ms +24.59% -1.25% 11.83%
domContentLoaded 860.54 ms +3.08% -0.85% 826.93 ms +0.75% -1.09% 4.06%
loaded 861.76 ms +3.07% -0.81% 828.41 ms +0.74% -1.1% 4.03%
firstContentfulPaint 479.28 ms +3.15% -2.14% 464.74 ms +0.48% -2.82% 3.13%
firstBlock 2640.9 ms +5.32% -3.08% 2488.64 ms +0.3% -0.15% 6.12%
type 17.25 ms +5.16% -10.49% 18.46 ms +16.14% -10.89% -6.55%
navigate 113.68 ms +7.2% -1.15% 107.02 ms +2.97% -2.92% 6.22%
loadPatterns 1449.21 ms +6.07% -14.19% 1528.54 ms +4.99% -9.41% -5.19%
loadPages 926.04 ms +2.34% -3.87% 918.64 ms +2.21% -0.79% 0.81%
wpTotal 397.45 ms +1.12% -10.05% 393.28 ms +0.61% -5.57% 1.06%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

f677058 Run

🏁 Flaky tests

Some 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.

Actions are reachable via RIGHT/LEFT arrow keys in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' })
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' }) with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page One Edit Actions' }).getByRole('button', { name: 'Edit' })
    14 × locator resolved to <button type="button" tabindex="-1" class="components-button is-small" id="view-list-0-192-primary-action-edit-post">Edit</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:172:5

f677058 Run

@github-actions github-actions Bot added [Package] Block editor /packages/block-editor [Package] E2E Tests /packages/e2e-tests labels Dec 2, 2026
@draganescu draganescu added the [Type] Bug An existing feature does not function as intended label Dec 2, 2026
draganescu and others added 10 commits December 3, 2026 00:20
The 20.2.0 release published the section the entry was in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ncern

Restoring a recorded selection is a decision about the whole canvas, but
each inner block controller made it on its own, in its own effect, while
other controllers were still replacing their clones. The fixes for that
needed retired clone IDs, identity mappings for created blocks and an
exception in the picking rules.

The root provider now owns one selection reconciler. Controllers register
their ID mappings with it, ask it to run when they take blocks from
outside, and tell it when they replace the clones the selection was on.
It runs once every controller has synced and makes at most one selection
change. It acts on a recorded selection only when the canvas did not
report that selection itself, such as one an undo brings back, so a record
that falls behind the caret never pulls the caret back.

The controller that holds a block is the nearest parent whose inner
blocks are controlled, for restoring and reporting alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t synced

Whether typing in a controller updates the recorded selection depends on
its entity, which the block editor cannot tell. Typing in one Navigation
block leaves the record on the last click, and the other copy mirroring
the typing would bring the caret back to it. The reconciler now applies a
recorded selection only through a controller that just took its blocks
from outside, as after an undo, which is the rule the controllers used to
follow on their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each controller now tells the canvas's reconciler where the selection was
before and after every edit it sends out, keyed by the blocks value it
replaced and the one it sent. An undo or a redo gives the controller one of
those values back by reference, so the reconciler knows which copy was
edited and where its caret was, and that copy shows the selection again.
This covers a copy of the same entity and a controller of another entity,
such as a second Template Part, whose own entity's selection the root never
reads. Nothing is added to the entity, the store or any public API.

The history applies only when the edited copy itself took the value back:
a copy that merely mirrors another copy's keystroke can sync it late and
must not pull the caret back. When the selection moves into another
controller, the focused field gives up focus, since it would otherwise
report its own caret as the selection when the undo changes its text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Undo from the other Navigation block now expects the caret back in the
edited block, and redo too. The undo across two Template Parts is no longer
a fixme; it only clicks into the second part, since typing there is not
recorded as an undo level of its own, on trunk as well. Adds the Post
Content case from #87845, and waits for every Post Content to be visible,
as suggested on #82706.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trunk now has #82706, which this branch already builds on, so its
side of the conflicts in useBlockSync, its tests and the e2e specs is
kept. From trunk's later #82706 test commit, the Post Content spec also
waits for both instances before clearing the selection. Also types the
focused element in blurFocusedField, which failed the type check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#82706 is in trunk with its own entry for the typing fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ion-once

# Conflicts:
#	packages/block-editor/CHANGELOG.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] E2E Tests /packages/e2e-tests [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants