close
Skip to content

Editor: Fix drag and drop to the top of the page#71241

Merged
talldan merged 2 commits intoWordPress:trunkfrom
karthikeya-io:fix/drag-and-drop-to-the-top
Aug 20, 2025
Merged

Editor: Fix drag and drop to the top of the page#71241
talldan merged 2 commits intoWordPress:trunkfrom
karthikeya-io:fix/drag-and-drop-to-the-top

Conversation

@karthikeya-io
Copy link
Copy Markdown
Contributor

@karthikeya-io karthikeya-io commented Aug 18, 2025

What?

Closes #71198

Why?

  • The drag and drop feature in Editor doesn't work as expected if useBlockProps used incorrectly or if the block doesn't render any markup.
  • Logs the following error in console Uncaught TypeError: Cannot read properties of null (reading 'getBoundingClientRect').

How?

  • Guard getElementById calls and return null if no block element exists and add null-safe checks around dropZoneElement.getBoundingClientRect()
  • In PostCommentsLinkEdit:
    • Remove early return null and render warning.

Testing Instructions

  1. While editing the template add the Comments Link block
  2. Check if drag and drop works as expected
  3. Confirm no errors in console

Testing Instructions for Keyboard

Screenshots or screencast

Before and After

Screen.Recording.2025-08-19.at.1.51.27.AM.mov

@karthikeya-io karthikeya-io marked this pull request as ready for review August 18, 2025 20:34
@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: karthikeya-io <karthikeya01@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Drag and Drop Drag and drop functionality when working with blocks labels Aug 19, 2025
Copy link
Copy Markdown
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, thanks for the fix, and for finding the block with the issue.

I also tested the drag and drop changes without the block fix, and it works well, so it means drag and drop will work better if a third party block might have this kind of bug.

@talldan talldan merged commit 5d56ce7 into WordPress:trunk Aug 20, 2025
76 of 81 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.5 milestone Aug 20, 2025
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Aug 20, 2025
* Fix: Guard drag-and-drop against missing block DOM nodes

* Fix: Ensure Post Comments Link always renders block wrapper

----

Co-authored-by: karthikeya-io <karthikeya01@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Drag and Drop Drag and drop functionality when working with blocks [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking on a block sometimes gets it dragged to the top of the page

3 participants