Skip to content

Capture/apply block-remove suggestions - #77968

Closed
adamsilverstein wants to merge 7 commits into
suggest-mode-6-foundationsfrom
suggest-mode-6a-remove-mechanism
Closed

adamsilverstein wants to merge 7 commits into
suggest-mode-6-foundationsfrom
suggest-mode-6a-remove-mechanism

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented May 5, 2026 •

Copy link
Copy Markdown
Member

What

Adds the data-layer mechanism for block-remove suggestions (#77434, task 6a). In Suggest mode a removeBlock dispatch no longer drops the block — the apply-and-tag flow re-inserts the subtree at its previous position and tags it with metadata.suggestion = { type: 'pending-remove' }. Auto-save persists the marker as a block-remove operation; Apply later runs the real removeBlock; Reject just clears the marker.

This PR ships the mechanism only — there is no visual treatment yet. Strikethrough/dim styling, summary, and diff variants land in the next PR (#77970).

Two commits

  1. Capture block removals as pending-remove markers — interceptor extension: per-tick tree snapshot (parent + index + full subtree), removal detection, top-level-only re-insert, marker stamp.
  2. Persist and apply block-remove suggestions — overlay reducer gets SET_STRUCTURAL_OP, auto-save's operationsForEntry emits the structural op, provider's applySuggestion branches on findStructuralOp and dispatches removeBlock, rejectSuggestion clears the marker.

Testing

  • 124 unit tests pass. Lint clean.
  • For full-stack testing instructions, see the foundations PR (#77967).

Stack

  1. #77967 — Schema v2 bump (foundations)
  2. #77968 — Capture block-remove (mechanism)
  3. #77970 — Render block-remove preview (UI)
  4. #77971 — Capture block-insert-after (mechanism)
  5. #77973 — Render block-insert-after preview (UI)
  6. #77978 — Capture block-move (mechanism)
  7. #77979 — Render block-move preview (UI)

Refs #77434, #73411.

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

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 props-bot label.

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: adamsilverstein <adamsilverstein@git.wordpress.org>

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

@github-actions

github-actions Bot commented May 5, 2026 •

Copy link
Copy Markdown

Size Change: +750 B (+0.01%)

Total Size: 7.52 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 485 kB +750 B (+0.15%)

compressed-size-action

@github-actions

github-actions Bot commented May 5, 2026 •

Copy link
Copy Markdown

Flaky tests detected in 008eb74.
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/25406047322
📝 Reported issues:

@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6-foundations branch from e6968d3 to a9ad146 Compare June 17, 2026 21:11
@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6a-remove-mechanism branch from 42d77e8 to 83baf50 Compare June 17, 2026 21:12
@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6-foundations branch from a9ad146 to 0ba06e2 Compare June 17, 2026 21:20
@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6a-remove-mechanism branch from 83baf50 to 6150237 Compare June 17, 2026 21:20
In Suggest mode a removeBlock dispatch must not actually remove the
block — the apply-and-tag flow re-inserts the subtree at its previous
position and stamps a metadata.suggestion = { type: 'pending-remove' }
marker on the re-inserted top-level block. Auto-save (in a follow-up)
reads the marker and persists it as a block-remove operation; Apply
later runs the real removeBlock, Reject just clears the marker.

The interceptor maintains a per-tick tree snapshot so the previous
position (parent + index) and full subtree are recoverable after the
block has already been dropped from the live tree. Re-insertion is
limited to top-level removed blocks — descendants of another removed
block ride along with their parent, and re-inserting them separately
would duplicate them.

`metadata.suggestion` is added to SYSTEM_METADATA_KEYS so subsequent
fires fold the marker into the snapshot rather than reverting it,
and so it never leaks into the user-pending overlay.

Refs #77434.
Wires the pending-remove marker through to the existing auto-save and
apply/reject paths so a removal in Suggest mode produces a real note
comment that the post author can Apply or Reject.

- overlay-context: adds a SET_STRUCTURAL_OP reducer action and a
  setStructuralOp helper. Structural ops live alongside attribute-set
  diffs in the overlay entry; the interceptor calls setStructuralOp
  immediately after tagging the live block.
- auto-save: operationsForEntry merges any structural op with the
  existing attribute-set diff before fingerprinting. The structural op
  leads so a Reject reverts to the pre-suggestion shape.
- provider: applySuggestion branches on findStructuralOp; for block-
  remove it clears the marker, drops the overlay, and dispatches
  removeBlock — three bypass-guarded dispatches so the interceptor
  doesn't fight the apply. rejectSuggestion accepts an optional
  clientId/payload and clears the marker for structural rejects so
  the dimmed/struck visual treatment goes away.
- collab-sidebar suggestion-actions: passes clientId + payload to
  rejectSuggestion so the marker-clear path runs.

Refs #77434.
…ging

When another client accepts a pending-remove suggestion, the
marker-clear plus the removeBlock arrive on this client through sync,
typically batched into a single block-editor update. The interceptor's
removal-detection branch was treating the disappearance as a fresh
user delete — re-inserting the block and tagging it pending-remove
again, which then bounced back through sync and undid the apply on
the accepting client a moment after they clicked.

Recognize the apply landing by checking the previous-tick tree
snapshot for `metadata.suggestion.type === 'pending-remove'` on the
disappearing block. When the marker is still there, drop the snapshot
entry and let the removal stand.

The PRUNE_ORPHANS effect in overlay-context cleans up the matching
overlay entry on the next render.
@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6-foundations branch from 0ba06e2 to 4ef811a Compare June 18, 2026 06:26
@adamsilverstein
adamsilverstein force-pushed the suggest-mode-6a-remove-mechanism branch from 6150237 to 9fb6c86 Compare June 18, 2026 06:28
@adamsilverstein adamsilverstein changed the title Suggest mode 6a: Capture and apply block-remove suggestions (mechanism) Suggest mode: Capture/apply block-remove suggestions Jun 30, 2026
@adamsilverstein adamsilverstein changed the title Suggest mode: Capture/apply block-remove suggestions Capture/apply block-remove suggestions Jun 30, 2026
@adamsilverstein

Copy link
Copy Markdown
Member Author

Superseded by the fresh-stack restructure of Suggest mode (#73411).

The feature has been re-sliced from this 16-deep stack onto current trunk as a clean 2-PR stack:

The whole feature now sits behind a Suggestion Mode experiment (Settings → Experiments → Collaboration). Closing in favour of the new stack — details: #73411 (comment)

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

Labels

[Feature] Notes Phase 3 of the Gutenberg roadmap around block commenting [Package] Editor /packages/editor [Status] In Progress Tracking issues with work in progress [Type] Feature New feature to highlight in changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant