Skip to content

Classic Block: Copy/paste broken for empty Classic Block#77719

Open
BugReportOnWeb wants to merge 1 commit intoWordPress:trunkfrom
BugReportOnWeb:fix/classic-block-on-empty-copy-paste
Open

Classic Block: Copy/paste broken for empty Classic Block#77719
BugReportOnWeb wants to merge 1 commit intoWordPress:trunkfrom
BugReportOnWeb:fix/classic-block-on-empty-copy-paste

Conversation

@BugReportOnWeb
Copy link
Copy Markdown
Contributor

What?

Closes #75798

Copy/paste from the block options menu does nothing for an empty Classic Block because it is invisible in the code editor when empty, unlike other block types (Image, Audio, Custom HTML, etc.).

Why?

An empty Classic Block serializes to empty HTML instead of a block comment delimiter. As a result, the clipboard receives no data when the block is copied or cut, so pasting produces no output.

By emitting a block comment when the Classic Block is empty and ensuring it is properly parsed (without being ignored), we allow empty Classic Blocks to be copied/cut and pasted correctly, while preserving the existing HTML parsing behavior when the block contains content.

How?

  • Emit <!-- wp:freeform /--> when the Classic Block’s saveContent is empty.
  • Only ignore implicit freeform blocks during parsing (rawBlock.blockName !== getFreeformContentHandlerName())
  • Use attributes?.content in the paste handler to distinguish and empty Classic Blocks from the legacy freeform blocks containing raw HTML

Testing Instructions

  1. Insert an empty Classic Block
  2. Copy or cut it using the block options menu, then paste
    • An empty Classic Block should be inserted
  3. Switch to the code editor and confirm <!-- wp:freeform /--> is present
  4. Repeat with a non-empty Classic Block
    • Content should copy and paste correctly
  5. (Optional) Paste raw HTML directly into the code editor
    • Legacy content handling should continue to work as before

Screenshots or screencast

Screen.Recording.2026-04-27.at.11.31.52.PM.mov

Use of AI Tools

Code assistance with GitHub Copilot and ChatGPT for rephrasing PR description.

@github-actions github-actions Bot added the [Package] Blocks /packages/blocks label Apr 27, 2026
@BugReportOnWeb BugReportOnWeb marked this pull request as ready for review April 27, 2026 19:11
@github-actions
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: BugReportOnWeb <devasheeshkaul@git.wordpress.org>
Co-authored-by: hiroshisatoy <hiroshisato@git.wordpress.org>

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

@yogeshbhutkar yogeshbhutkar added the [Type] Bug An existing feature does not function as intended label Apr 28, 2026
@t-hamano t-hamano added the [Block] Classic Affects the Classic Editor Block label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Classic Affects the Classic Editor Block [Package] Blocks /packages/blocks [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy/Cut from block options menu does not work in empty Classic Block (7.0-beta1)

3 participants