Skip to content
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

Drag and drop indicator line positioning is incorrect in WP Playground #58756

Closed
andrewserong opened this issue Feb 7, 2024 · 9 comments · Fixed by #58932
Closed

Drag and drop indicator line positioning is incorrect in WP Playground #58756

andrewserong opened this issue Feb 7, 2024 · 9 comments · Fixed by #58932
Assignees
Labels
[Feature] Drag and Drop Drag and drop functionality when working with blocks [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@andrewserong
Copy link
Contributor

andrewserong commented Feb 7, 2024

Description

Raised by @annezazu in #58589 (comment): the drop indicator line (BlockPopoverInbetween) when dragging and dropping into the editor canvas is in the wrong position when using WP Playground.

WP Playground renders the editor lower down within the page, with its own chrome added to the top of the page. It appears that this change means that the positioning of the drop indicator line is off.

Ideally, the drop indicator line logic should be resilient to the editor being rendered in a different position to flush against the top of the viewport.

Step-by-step reproduction instructions

  1. Go to https://playground.wordpress.net/ or https://playground.wordpress.net/gutenberg.html to test with a Gutenberg PR
  2. Open up the site editor, and go to drag a Heading block from the block inserter to the left or right of a block within the template
  3. Notice that the drop indicator line is in the incorrect position vertically (by roughly the same distance as the height of the Playground chrome)

Screenshots, screen recording, code snippet

In this screenshot, note how the drop indicator line is lower than the position of the Buttons block we're trying to drag next to:
image

This doesn't happen in a "normal" Gutenberg/WP environment

Environment info

  • Gutenberg trunk, specifically testing using WP Playground

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

@andrewserong andrewserong added [Type] Bug An existing feature does not function as intended [Feature] Drag and Drop Drag and drop functionality when working with blocks labels Feb 7, 2024
@andrewserong
Copy link
Contributor Author

Note: this issue isn't exclusive to drag and drop — it also affects the inbetween inserter when hovering between blocks. For example, in the following screenshot, this should have displayed above the Image block:

image

@t-hamano
Copy link
Contributor

t-hamano commented Feb 7, 2024

The root cause of this issue may be the same as reported #58001 for popover and space visualizer issues.

@andrewserong
Copy link
Contributor Author

Thanks @t-hamano! Yes, that helps — sounds like there's a disconnect between the measurements that the popover is using, and then what happens when the positioning is output for it 🤔

@andrewserong
Copy link
Contributor Author

andrewserong commented Feb 8, 2024

Just in case it helps anyone else with debugging, I can reproduce this issue outside of WP Playground by adding a wrapper.html file into the Gutenberg directory, and then accessing it via http://localhost:8888/wp-content/plugins/gutenberg/wrapper.html — here's an example wrapper.html (assuming you're using wp-env and your dev site is hosted at localhost:8888):

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Gutenberg in an iframe</title>
</head>
<body>
    <div class="header">
        <p>This is a header</p>
    </div>
    <iframe class="editor" src="http://localhost:8888/wp-admin/site-editor.php" title="Test site">

    </iframe>
    <style>
        .header {
            background-color: #f4f4f4;
            padding: 20px;
            text-align: center;
        }

        .editor {
            width: 100%;
            height: 100vh;
            border: none;
        }
    </style>
</body>
</html>

That then results in the inbetween inserter rendering lower than expected (the same distance lower at the height of the header area):

image

Unfortunately, I haven't had much luck debugging this, and I can't quite work out if it's a recent issue, or a limitation of floating-ui's iframe awareness, in that it sounds like it should be working up the hierarchy of iframes, but perhaps it doesn't consider whether the outer-most document is itself in an iframe? Just pinging @ciampo who previously worked on #46845 which removed the old overrides to offset iframes, and @jsnajdr who worked on a floating-ui fix that was surrounding traversing up into the iframe parent: floating-ui/floating-ui#2535

I wonder if the problem is to do with floating-ui, the popover component, or how we use popover slots? Incidentally, if I force the editor canvas to be rendered without an iframe (by enabling Custom fields in the editor preferences) then the positioning issue doesn't appear. So to isolate the problem it seems to be present when we're measuring an element or position that is within the editor canvas iframe (i.e. blocks in the canvas) and the whole editor itself is iframed (as in WP Playground).

@jsnajdr
Copy link
Member

jsnajdr commented Feb 8, 2024

I see you're putting the Site Editor in iframe, and the Site Editor page then creates one more nested iframe for the edited content. Yes, that indeed triggers a known bug in Floating UI! The library can't handle two nested iframes and will calculate positions incorrectly. We've been discussing this with @ciampo several times 🙂 But the only place where this manifested so far was Storybook, never a production situation, so it's been a low priority issue I never got around to fix. Does it become high priority now?

@youknowriad
Copy link
Contributor

Yes this issue can be reproduced easily on storybook https://wordpress.github.io/gutenberg/?path=/story/playground-block-editor--box

@bph
Copy link
Contributor

bph commented Feb 8, 2024

This also seems to be an issue with the Block Toolbar location covering part of the block it belongs, too.

I originally thought it was a button block regression issue, but when I tested things in a LocalWP environment, it didn't occur.

All Screenrecording and screenshot via Playground

Attempt.to.edit.the.button.mp4

It also happens with other blocks: Example paragraph block + Image block
Screenshot 2024-02-08 at 11 11 12

Screenshot 2024-02-08 at 11 21 14

Screenshot 2024-02-08 at 11 21 34

@andrewserong
Copy link
Contributor Author

But the only place where this manifested so far was Storybook, never a production situation, so it's been a low priority issue I never got around to fix. Does it become high priority now?

Thanks for confirming, folks! Yes, it's become a higher priority now that Playground use is becoming more prominent. Since it's a very convenient way for folks to test out WordPress and Gutenberg features, I think that's probably why we're seeing more reports of the issue.

@jsnajdr
Copy link
Member

jsnajdr commented Feb 9, 2024

I submitted a Floating UI fix here: floating-ui/floating-ui#2785

Let's see what the maintainer says about it. If a new patched version is released, we can upgrade the Gutenberg dependency and that should fix the Playground problem.

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 [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants