-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block draggable chip's position is incorrect when dragging over an iframe #55074
Comments
I'm not sure what's caused this one, but from logging out the event in the This is where I was looking: gutenberg/packages/components/src/draggable/index.tsx Lines 188 to 203 in f36f4cd
|
Mhh, since Normally iframes should act as a black hole and absorb all pointer events, but our iframe actually bubbles some of these events (as I recently learned). I can see that #54080 introduced some changes to that functionality, I wonder if it could be related, or at least a good starting point. |
Oh, thank you @t-hamano! Apologies for missing your earlier report in that issue, I did a quick skim for issues that already flagged this, but my search was not thorough enough 🙂
Thank you both for identifying this one as the culprit! That's a big help, I was definitely scratching my head trying to figure out what could've changed 😄 I wonder if we can get the Draggable component to provide an offset if the event is coming from an iframe, so that to a user there's no discernible jump? I'll have a play around. |
Interestingly I found that I can get this issue working properly in the editor again (I think!) if I comment out the check over in
Without that check, the position seems okay: 2023-10-06.14.38.13.mp4I do notice there's a bit of a performance hit when dragging over the iframe, possibly due to the cost of the I've added a question about the above check in Happy to continue digging on Monday if that doesn't get us there, though! |
I also noticed some jankiness, and calling |
I found that I could solve the problem by changing the following: diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js
index 9a6371dcaf..badbbfd2b9 100644
--- a/packages/block-editor/src/components/iframe/index.js
+++ b/packages/block-editor/src/components/iframe/index.js
@@ -38,7 +38,7 @@ function bubbleEvent( event, Constructor, frame ) {
init[ key ] = event[ key ];
}
- if ( event instanceof frame.ownerDocument.defaultView.MouseEvent ) {
+ if ( event instanceof frame.contentDocument.defaultView.MouseEvent ) {
const rect = frame.getBoundingClientRect();
init.clientX += rect.left;
init.clientY += rect.top; Before being refactored in #54080, it appears to be checking if the current event is an instance of the iframe document itself. On the other hand, the refactored code seems to check if the event is an instance of the iframe's parent document. So should we check the current document ( |
@t-hamano we both found the same thing at the same time! I have a PR up over in #55150 😄 Note: it doesn't address the issue of Storybook in the Docs view, since Storybook doesn't receive the offset logic in our Iframe component. I reckon we could leave that issue aside for now, as fixing that would likely involve moving the offset logic to the |
Description
The drag chip (the little icon that follows the mouse cursor around) is incorrectly positioned when dragging a block over the site editor canvas, or the post editor canvas when the post editor is iframed (i.e. running TT3 theme with core blocks).
This appears to be to do with the
Draggable
component's positioning when dragging over an iframe in particular.Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
2023-10-05.16.55.20.mp4
The same issue appears to happen with the Draggable component in Storybook if you use the Docs view that shows all stories. This is a good way to test it because each preview occurs in an iframe, too, it seems. The URL for testing the Draggable component in Storybook is: https://wordpress.github.io/gutenberg/?path=/docs/components-draggable--docs
2023-10-05.16.57.57.mp4
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: