Skip to content

Suggestion mode 3/9: block-level capture (attribute and structural) - #80429

Open
adamsilverstein wants to merge 129 commits into
suggest/datafrom
suggest/block-capture
Open

adamsilverstein wants to merge 129 commits into
suggest/datafrom
suggest/block-capture

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Part of #73411

What's in this PR

Adds block-level capture: in Suggesting, an edit to a block is written onto the block's metadata.suggestion marker instead of being applied.

  • The setAttributes HOC (with-suggestion-overlay.tsx) writes an attribute edit into the marker's proposal (after) and leaves the live attributes at the baseline. In every mode it renders the block with the proposal merged over the live attributes, so everyone sees what is proposed.
  • The store interceptor (store-interceptor.ts) catches changes dispatched straight to the block-editor store (the block switcher's variation picker, programmatic writes). It routes attribute drift into the same proposal and reverts the live block, and it captures structural edits (insert / remove / move, list indent and outdent) by tagging the live block with a pending-insert, pending-remove or pending-move marker and recording the operation.
  • Pending treatments: the bracket on a block with a proposal, the strikethrough on a pending removal, the outline on a pending insert, and the ghost at a pending move's origin.
  • Guards: the revert guard keeps the interceptor out of its own subscribe loop, and the undo guard makes undo withdraw a suggestion instead of being captured as a new one.
  • Server: pending insertions are hidden at render time, and a pending move renders in its original order.

Inline text and formatting markers are layered on top of this HOC in #80433.

Screenshot

Structural suggestions keep the block on the canvas and tag it instead of applying the change. A suggested move lands the block at its proposed position and leaves a ghost at the origin; a suggested removal keeps the block with a struck-through treatment:

Editor canvas showing a Suggested move badge, a Moved from here ghost, and a struck-through pending removal, each with its note

Testing

This is one layer of the stack. To exercise the whole feature, #78994 bundles every layer into one branch and builds it in Playground:

Test in WordPress Playground

👉 https://playground.wordpress.net/gutenberg.html?pr=78994

Enable Gutenberg > Experiments > Collaboration > Suggestion Mode, then follow the walkthrough in #73411, which also explains how to review the stack layer by layer.


Suggestion mode stack

This rebuilds the manually-stacked Suggestion mode work (#73411) as a GitHub Stack of 9 small, independently reviewable PRs, each building on the one below it:

  1. #80427 - editor intent (edit/suggest) + experiment gate
  2. #80428 - suggestion storage, REST controller, provider
  3. #80429 - block-level capture (attribute + structural)
  4. #80430 - inline marker primitive
  5. #80431 - inline suggestion operations
  6. #80432 - review UI (Apply/Reject sidebar + summary)
  7. #80433 - inline live wiring
  8. #82047 - architecture documentation
  9. #82048 - end-to-end test suite

Each follow up fix now sits in the layer that owns the code it changes, rather than piling onto the top of the stack. Overlapping suggestions were briefly their own layer (#86206, now closed); that code sits in the layers that own it, mainly #80431 and #80433. The whole feature can be exercised end-to-end via the combined testing branch #78994 (Playground). Behind the "Suggestion Mode" experiment (Gutenberg > Experiments).


AI Use

Code and description both written with 🤖 Claude Code. I will review and test.

Adds the store-level interceptor that catches block mutations dispatched
straight to the block-editor store (the block-switcher variation picker,
programmatic writes), routing attribute drift into the overlay and reverting
the live block; captures structural edits (insert/remove/move) by tagging
the live block with a metadata.suggestion marker and recording the op; and
the overlay HOC that renders the pending-suggestion visual treatment (the
green attribute bracket and the strikethrough/dim/move-ghost overlays). The
revert guard and undo guard keep the interceptor's own writes off the undo
stack and out of its own subscribe loop, and the server hides un-accepted
structural insertions at render time. Inline text and formatting markers
are layered on top of this HOC in a later step.
@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Size Change: +7.4 kB (+0.09%)

Total Size: 7.93 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 592 kB +5.21 kB (+0.89%)
build/styles/block-editor/content-rtl.css 6.21 kB +563 B (+9.97%) ⚠️
build/styles/block-editor/content-rtl.min.css 4.67 kB +530 B (+12.82%) ⚠️
build/styles/block-editor/content.css 6.21 kB +561 B (+9.93%) ⚠️
build/styles/block-editor/content.min.css 4.66 kB +532 B (+12.88%) ⚠️

compressed-size-action

@adamsilverstein adamsilverstein added No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Type] Feature New feature to highlight in changelogs. labels Jul 17, 2026
@adamsilverstein
adamsilverstein marked this pull request as ready for review August 5, 2026 22:24
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Flaky tests detected in ec6ef6b.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/33450977039
📝 Reported tests:

user-customized templates cannot be overridden by plugins in /test/e2e/specs/site-editor/template-registration.spec.js, passed after 1 failed attempt.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → PUT http://localhost:8889/wp-json/wp/v2/plugins/gutenberg-test-plugins/block-template-registration
    - user-agent: Playwright/1.62.1 (x64; ubuntu 24.04) node/20.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: c8e65a6bd0
    - content-type: application/json
    - content-length: 19
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1788392184%7C2czyilfVTPsdqLCbNIaRnBazfnLzIbQD7OmKs00O4XO%7C494f33da252f3af01034a1331fc876be1ecb879b47214eb0a6d3376be24f3cba; wp-settings-time-1=1788220298

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:112:39)
    at RequestUtils.activatePlugin (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/plugins.ts:72:13)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/template-registration.spec.js:295:3

… layer

Merge branch 'suggest/data' into suggest/block-capture.

The storage layer now carries the marker design, so the capture layer
builds on it directly instead of on the in-memory overlay a later layer
removed. The HOC writes attribute proposals into the block's
`metadata.suggestion.after` and renders them merged over the live
attributes, the store interceptor routes store-level drift to the same
marker and records structural captures on the session, and the undo
guard orders those captures against history-owned proposal writes.

The inline marker hand-offs (format and content reconciliation, refused
edits) stay with the layer that wires inline suggestions.

Claude-Session: https://claude.ai/code/session_018vwYjU3KeQ4xVQPLeAzqZz
…pture layer

A later layer changed how edits to another author's suggested block are
captured: a move, removal or attribute change there now nests as a
suggestion of its own instead of folding into theirs, and the block
shows every author's proposal. Capture and show them that way from the
start, so the capture layer does not ship the folding model only to
rewrite it.

Claude-Session: https://claude.ai/code/session_018vwYjS1afuMwCEzNKqAxg6
# Conflicts:
#	packages/editor/src/store/reducer.js
#	tools/eslint/suppressions.json
Each editor's undo guard wrapped the actions on the core-data object all
editors share, so one editor's undo ran every editor's guard, and
unmounting out of order left a stale wrap behind or dropped a live one.
Register the guard as the interceptor of its own editor's undo and redo
instead, the surface every in-editor caller already goes through.
The store interceptor diffed every block in the canvas, so an edit inside a synced pattern, a template part or a navigation menu wrote a marker into that entity, where the save pass never looks, and the blocks a controlled container loaded were proposed as insertions. With the template shown it also captured edits to the template itself.

Add one ownership check, following the nearest ancestor with controlled inner blocks, and have the interceptor adopt any block the post does not own.
While suggesting, the overlay turned an edit to a synced pattern's, template part's or navigation menu's block into a proposal marker saved in that entity. Writing it through instead would be a direct edit made in Suggesting. Decline it with a notice, as an edit to a site setting already is.
Assigning refs during render can leave a ref holding a value from a render
React threw away. useEvent gives the interceptor's subscribe callback and
the wrapped undo the latest session callbacks without resubscribing, and
drops seven react-hooks/refs suppressions.
The comment still named the overlay context, which became the suggestion
session.
Proposals are stored on the block, so there is no overlay to contrast
with or to retire.
The suggest intent is now refused without the experiment.
The canvas merged a block's proposal into the attributes its edit
component renders, before any decision and without the checks accept
runs. Any author of the post can write a marker, so a proposed element
name or URL scheme reached the reviewer's canvas as written.

The displayed proposal now goes through the same validation as accept.
A value that fails stays at its baseline in the canvas, while the note
still describes it and accepting it is still refused.
The suggest intent is refused without it, so the interceptor never started.
…llback

The ref it read was replaced by useEvent, so removing a block from a controlled block threw.
The session read the user once, so one that began before the user resolved wrote every marker without an author, and those are never saved.
…n capture

An authorless marker no longer belongs to the viewer, so an edit inside one is a proposal like an edit inside another author's.
A pending insertion was rendered in full and its output dropped on
render_block, so its render callback and those of its inner blocks
still ran and enqueued their assets on the front end. Short-circuit it
on pre_render_block, after core's callbacks, which reset the value to
null. The render_block filter stays for a block rendered directly.
…tions

The interceptor recorded the whole block on a block-remove or
block-insert-after capture, which auto-save then sent as the note's payload.
A large block took the payload over the 64 KB cap, the note was refused, and
the marker stayed in content with nothing to decide it by. The capture now
carries the block's excerpt, like an operation derived from a marker.
The capture callbacks are read through useEvent, so nothing in this layer's interceptor holds a ref.
Deleting from the middle of one block to the middle of another left one attribute note and one removal note per block, each decided on its own, so accepting one left the post half deleted. The rewritten block and the removed ones now share a group id, as the halves of a block transform do (#87283, F-52).

Claude-Session: https://claude.ai/code/session_018vwYjTYKPCN8vz5C4CntuY
A block rendered in a preview is not part of the post. The previewed Navigation block in the Template panel wrote its ref once its menu resolved, which was refused with a "saved outside this post" notice (#87283, F-68).

Claude-Session: https://claude.ai/code/session_018vwYjTYKPCN8vz5C4CntuY
@adamsilverstein adamsilverstein changed the title Suggestion mode 3/10: block-level capture (attribute and structural) Suggestion mode 3/9: block-level capture (attribute and structural) Nov 28, 2026

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

No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core [Package] Block editor /packages/block-editor [Package] Editor /packages/editor [Type] Feature New feature to highlight in changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants