Repository navigation
Block Editor: Include resolved bound content when copying blocks - #84428
salvatorecorsi wants to merge 14 commits into
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @salvatorecorsi! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
ciampo
left a comment
There was a problem hiding this comment.
I don't have the full context on the block bindings work, but I took a look from the menu and clipboard side and left a few comments inline. Please don't count me as the main reviewer for this one.
| ( Window & typeof globalThis ) | null; | ||
| if ( view?.navigator.clipboard?.write && view.ClipboardItem ) { | ||
| try { | ||
| await view.navigator.clipboard.write( [ |
There was a problem hiding this comment.
In WebKit 27.2, this write succeeded, but the paste event contained the visible text and had lost the block comments carrying metadata.bindings. The copy-event fallback preserved both in the same check. Could we use a write path that preserves the binding and cover copying from the menu and pasting back into Gutenberg in WebKit?
There was a problem hiding this comment.
The hosted WebKit test now passes when copying from Options and pasting back into Gutenberg. Could we also force the copy event to fail and check that Cut followed by Paste keeps the binding? Cut removes the original as soon as the async write reports success.
There was a problem hiding this comment.
I replaced the async HTML fallback with a serialized text write, because a successful HTML write can still strip the binding comments. In the native Chromium post editor, I forced the copy event to fail and held the real text-write promise: Cut kept the source until success, then Paste retained its binding and content.
| 'text/html': new view.Blob( [ content.html ], { | ||
| type: 'text/html', | ||
| } ), | ||
| 'text/plain': new view.Blob( [ content.plainText ], { |
There was a problem hiding this comment.
Copying a styled bound paragraph from Options used to work with Paste styles. usePasteStyles reads only text/plain, which now contains just the visible text, so it reports that it couldn't find any styles. Could we have Paste styles use the serialized block when it's available and cover that pair of commands?
There was a problem hiding this comment.
The Chromium test now copies a bound paragraph from Options and applies its font size to the target paragraph. That covers the case I raised here.
| : getClipboardBlocksContent( | ||
| getBlocksByClientId( clientIds ) as Block[], | ||
| registry, | ||
| attributesForCopy |
There was a problem hiding this comment.
Copying a bound List Item from an ordered list produces a bare <li> here. Could the rich menu copy honor requiresWrapperOnCopy so it retains the parent <ol> the same way keyboard copy does?
There was a problem hiding this comment.
The ordered list now pastes with its wrapper. I found one side effect for Paste styles. With a large bound List Item inside a small List, copying the item applies small to the target. Could we keep the wrapper for regular paste and use the selected item's styles for Paste styles?
There was a problem hiding this comment.
Paste styles now reads the selected item’s styles while normal paste keeps the ordered-list wrapper. A clipboard-only marker distinguishes a synthetic wrapper from an actually selected List and is removed before insertion, so copying the List itself still uses its own styles.
| registry, | ||
| attributesForCopy | ||
| ), | ||
| () => serialize( getBlocksByClientId( clientIds ) as Block[] ), |
There was a problem hiding this comment.
For an unbound selection, getClipboardBlocksContent has already serialized these blocks. Could we reuse that markup for the text-only write so Copy and Cut only serialize the selection once?
There was a problem hiding this comment.
Unbound Copy and Cut now reuse the serialized markup for the text write. That addresses my comment here.
|
Thanks for checking these clipboard paths. The update in 53cf427a tries the synchronous copy event first so the block comments can travel with the visible text. Paste styles reads the serialized HTML when available and still accepts the existing serialized text format. Menu copy keeps the ordered-list wrapper for a bound item, and unbound Copy and Cut reuse the same serialization. I verified the menu copy, pasting back with the binding, and Paste styles in the actual post editor in Chromium. The menu round trip is also in the WebKit Playwright project. My Windows WebKit 27.2 build did not return the rich clipboard payload even in a minimal copy-event control, so the Safari round trip still needs confirmation. |
| .filter( | ||
| ( [ attributeName, binding ] ) => | ||
| bindableAttributes?.includes( attributeName ) && | ||
| registeredSources[ binding?.source as string ] |
There was a problem hiding this comment.
With testing/server-only-source, the paragraph stores "paragraph default content" and the editor displays "Server Source". Copying the block now makes "Server Source" the pasted paragraph's saved content. Could we preserve the original fallback when the editor only has a placeholder? The existing server-only fixture would cover this.
There was a problem hiding this comment.
Thanks :D Server-only sources now stay out of the editor snapshot, because their displayed text is a placeholder rather than a value we can save. Copy retains the paragraph’s saved fallback; the regression covers a source without getValues.
| if ( | ||
| attributes !== block.attributes || | ||
| ! boundAttributeNames.length || | ||
| boundAttributeNames.some( |
There was a problem hiding this comment.
If a Button binds both text and url, and there's no saved URL, a source that returns only the text fails this check. Copy can then produce an empty button even though its label is visible. Could we keep each resolved attribute and use the saved fallback for the missing one?
There was a problem hiding this comment.
The snapshot now keeps resolved attributes individually, so a missing URL no longer drops the Button’s resolved label. Any saved URL fallback is preserved too.
| ( Window & typeof globalThis ) | null; | ||
| if ( view?.navigator.clipboard?.write && view.ClipboardItem ) { | ||
| try { | ||
| await view.navigator.clipboard.write( [ |
There was a problem hiding this comment.
The hosted WebKit test now passes when copying from Options and pasting back into Gutenberg. Could we also force the copy event to fail and check that Cut followed by Paste keeps the binding? Cut removes the original as soon as the async write reports success.
| : getClipboardBlocksContent( | ||
| getBlocksByClientId( clientIds ) as Block[], | ||
| registry, | ||
| attributesForCopy |
There was a problem hiding this comment.
The ordered list now pastes with its wrapper. I found one side effect for Paste styles. With a large bound List Item inside a small List, copying the item applies small to the target. Could we keep the wrapper for regular paste and use the selected item's styles for Paste styles?
| 'text/html': new view.Blob( [ content.html ], { | ||
| type: 'text/html', | ||
| } ), | ||
| 'text/plain': new view.Blob( [ content.plainText ], { |
There was a problem hiding this comment.
The Chromium test now copies a bound paragraph from Options and applies its font size to the target paragraph. That covers the case I raised here.
| registry, | ||
| attributesForCopy | ||
| ), | ||
| () => serialize( getBlocksByClientId( clientIds ) as Block[] ), |
There was a problem hiding this comment.
Unbound Copy and Cut now reuse the serialized markup for the text write. That addresses my comment here.
What?
See #84362. Related to #84389, which handles fully selected bound RichText separately.
Include available client-resolved binding values when copying blocks from the canvas, List View and the options menu. Preserve the binding definitions and saved fallbacks when an attribute cannot be resolved. Server-only editor placeholders must not become saved content.
Why?
Block serialization uses stored attributes, so a bound paragraph can look populated while its copy is empty. Treating all bound attributes as one snapshot also loses a resolved Button label when its URL is unavailable. An asynchronous HTML clipboard write can strip the comments carrying block metadata, which is especially harmful after Cut removes the original.
Copying an individual bound List Item needs its parent wrapper for normal paste, while Paste styles needs the selected item's styles.
How?
Record computed attributes from eligible mounted block edits in the existing per-editor refs context and apply them to copies of the selected tree. Only client sources with
getValuescontribute snapshots, and available values are applied attribute by attribute. Missing values retain their saved fallback. Stale, ambiguous, preview and Query Loop snapshots remain excluded.Canvas, List View and menu copies use the same payload builder. The menu first writes HTML and visible plain text through a synchronous copy event. If that event is unavailable, it writes the full serialized markup as text so the block comments survive. Cut removes the source only after that write succeeds. Unbound menu copying and Copy styles retain their existing transport.
A clipboard-only prefix identifies a synthetic parent wrapper. Normal paste consumes the prefix and keeps the wrapper; Paste styles consumes it and reads the selected children instead. Copying an actual List still uses the List's styles. Existing Windows fragment and Chromium metadata normalization is shared before reading the prefix.
Testing Instructions
Bound <strong>text</strong>, while its saved content is empty. Add a normal paragraph and an empty paste target.Bound textand a rich destination keeps its formatting.metadata.bindings. The original block and the source value should be unchanged.testing/server-only-sourcewith saved fallback content. Copy must preserve the fallback rather than save the editor's placeholder.largebound List Item inside asmallordered List. Normal paste should keep the ordered wrapper, and Paste styles should uselarge. Copying the List itself should still usesmall.Testing Instructions for Keyboard
Copy with Ctrl+C/Cmd+C and paste with Ctrl+V/Cmd+V. Repeat from List View and extend the selection with Shift+ArrowDown. The options-menu fallback was also checked with a real Cut followed by native Ctrl+V in the post editor.
Current validation — 22 November 2026
Published head
2e8faea22fb4b4d2dc1727da92dd5ce9b68d6903addresses the four requested follow-ups.The Chromium check uses a controlled promise gate around an actual write; it does not measure clipboard latency. The platform payload cases in unit tests are modeled inputs. No local Safari/WebKit, Docker E2E, full repository functional suite or full published-dependency audit is claimed for this follow-up. Hosted CI and the required type label remain separate from these local results.
Could a maintainer add the
[Type] Buglabel? I do not have permission to apply upstream labels.Use of AI Tools
OpenAI Codex assisted with investigation, implementation, regression tests, automated source review and validation, including the focused native-editor Chromium adapter. Maintainer review is requested.