Phase 3: Add suggestion diff preview, Apply, and Reject#77405
Draft
adamsilverstein wants to merge 1 commit intosuggest-mode-phase-2from
Draft
Phase 3: Add suggestion diff preview, Apply, and Reject#77405adamsilverstein wants to merge 1 commit intosuggest-mode-phase-2from
adamsilverstein wants to merge 1 commit intosuggest-mode-phase-2from
Conversation
This was referenced Apr 16, 2026
|
Size Change: +1.84 kB (+0.02%) Total Size: 7.75 MB 📦 View Changed
ℹ️ View Unchanged
|
edf102e to
fa199f5
Compare
7e2fe59 to
9debb13
Compare
fa199f5 to
36fc92e
Compare
f63fe8c to
66f2542
Compare
36fc92e to
8043af8
Compare
66f2542 to
5f968da
Compare
b1af20a to
6ae1fa6
Compare
5f968da to
8e41010
Compare
6ae1fa6 to
b09c96d
Compare
Phase 3 of the Suggest mode effort. Implements the Apply/Reject lifecycle and inline diff preview for suggestion notes. New in provider.js: - applySuggestion: applies operations to block attributes via updateBlockAttributes, marks note resolved with status 'applied'. Emits a warning snackbar when baseRevision differs from current post modified date (stale suggestion). - rejectSuggestion: marks note resolved with status 'rejected' without changing content. - applyOperations: pure function running attribute-set ops against current block attributes. - parseSuggestionPayload: safe JSON parser for _wp_suggestion meta. New SuggestionDiff component: - Word-level LCS-based diff for text attributes (insertions green underline, deletions red strikethrough). - Attribute label for non-text changes. UI integration in collab-sidebar/comments.js: - SuggestionActions component rendered inside CommentBoard when thread has _wp_suggestion meta. Shows diff + Apply/Reject buttons for pending suggestions, or Applied/Rejected label for resolved. Tests: applyOperations, parseSuggestionPayload, wordDiff (25 total). Refs #73411
8e41010 to
31a0ce8
Compare
|
Flaky tests detected in 31a0ce8. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24542672231
|
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.
Overview
This is one of 5 stacked PRs implementing Suggest mode for the WordPress editor — a Google Docs–style workflow where reviewers can propose changes that the post author can Accept or Reject. Tracked in #73411, with design direction from #73410 and jasmussen's mockups.
Architecture & Yjs readiness
The eventual long-term storage primitive for suggestions is the Yjs
AttributionManagerarriving in Yjs v14 (PR #77005), which attributes CRDT document changes to specific clients — exactly what suggested edits need. However, Yjs v14 is pre-release with an unstable API, and even with Yjs, server-side persistence is still needed for non-RTC users.Rather than block on Yjs, this series builds the full feature now with a comment-meta backend behind a swappable
SuggestionsProviderinterface shaped to match Yjs attribution semantics:attribute-set) — not HTML diffs — so they map directly to whatAttributionManagerwould emit.createSuggestion,updateSuggestion,deleteSuggestion,applySuggestion,rejectSuggestion. Today's implementation reads/writes comment meta; a futureyjs-provider.jscan drop in with the same methods.When #77005 stabilizes, the migration is: implement
yjs-provider.jsagainst the same interface, useAttributionManagerfor live-session attribution, and keep comment-meta as the fallback for users without RTC.The 5 phases
editorIntentpreference (edit/suggest/view), a mode selector in the Options kebab, read-only gating for View intent, keyboard shortcuts, and a "You're suggesting/editing/viewing" snackbar on mode change.editor.BlockEditfilter divertssetAttributesinto a React context so the user sees their edit live but the block-editor store stays at the baseline. The HOC is split so non-Suggest intents only run a singleuseSelect._wp_suggestioncomment meta, theSuggestionsProviderinterface (create/update/delete/apply/reject), and the accept/reject icon buttons in the notes sidebar.This PR (Phase 3)
Adds the persistence layer and review UI:
_wp_suggestioncomment meta — registered onnotecomments as a JSON payload (schemaVersion,blockName,baseRevision,operations). Payload size capped at 64 KB via asanitize_callback._wp_suggestion_statuscomment meta — lifecycle flag (pending/applied/rejected) with a REST-exposed enum.SuggestionsProviderinterface (useSuggestionsProvider()):createSuggestion,updateSuggestion,deleteSuggestion,applySuggestion,rejectSuggestion. Implementations can swap in without touching the UI — the Yjs-backed provider drops in with the same methods.applyOperations— pure function that applies an ordered list ofattribute-setoperations to a block's current attributes.SuggestionDiff— word-level LCS diff rendered in the notes sidebar with green underlined insertions and red strikethrough deletions. Falls back to a compact before→after label for non-text attributes.What's NOT in this PR
Phase 3 test plan
createSuggestion→ confirm aPOST /wp/v2/commentswithtype=noteand a_wp_suggestionmeta JSON body_wp_suggestion_statusis set toapplied_wp_suggestion_statusis set torejectednpm run test:unit -- packages/editor/src/components/suggestion-mode/test/provider.jsnpm run test:unit -- packages/editor/src/components/suggestion-mode/test/suggestion-diff.js🗺️ PR Stack Navigation
_wp_suggestionmeta, provider, sidebar actions📋 Tracking issue: #73411