-
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
Image Block is replaced as a Youtube block after dragging multiple blocks outside their parent #61778
Comments
I can also reproduce this on the Gutenberg trunk. I can reproduce the issue with WP 6.5 and no Gutenberg plugin. The order in which Image and Embed blocks are placed also doesn't matter. What's happening
|
I can reproduce this. When both an Image and Embed block are selected and dragged to a new location, the React UI for both will be unmounted and re-mounted at the new location. The Embed block has this effect with a gutenberg/packages/block-library/src/embed/edit.js Lines 169 to 187 in 608b890
But this gutenberg/packages/block-editor/src/components/block-list/block.js Lines 270 to 280 in 608b890
Because both the Embed and Image blocks are selected, the Image block's gutenberg/packages/block-library/src/image/image.js Lines 248 to 256 in 608b890
@youknowriad @ellatrix This behavior where function Edit( { attributes, setAttributes } ) {
<button onClick={ () => setAttributes( { foo: 'bar' } ) }>set</button>
} and the intent is quite obviously to set the attributes of exactly one block. And yet it's setting |
Thanks for finding the attribute update cause, @jsnajdr! I should've guessed it was a multi-selected block attribute update. Jarda, do you plan to work on a fix? I have an idea for an Embed block "hotfix" and happy to push it. P.S. This proves again that "on-mount effects" should be avoided in blocks or used very carefully. |
I think that the Embed block doesn't do anything wrong. It simply wants to update its own attributes, that's legit. The problem is that the |
Should we add some early returns in that setAttributes action? It should only update a multi-selection if the blocks are of the same type. I believe there are checks on render, but not in that action. |
That will only partially solve the issue. If you drag multiple embed blocks with different URLs, they'll have the same URL after the dragging. Edit: The original logic was introduced in #22470. |
This is still wrong, because if I select and drag two adjacent YouTube Embed blocks, they will update each other's URLs. The question is more like: why is |
I don't think we can just remove current behavior, as it would be considered a breaking change. FYI, updating values for multiple blocks of the same type also has issue #51609. |
Oh I'm very happy to see everyone's response in my bug report. Unfortunately I yet lack the knowledge to contribute beyond filing a report. I would be completely lost creating pull requests, committing changes etc. I guess no further actions are required from me, is that correct ? |
Thanks for reporting the bug, @jeflopodev! That's right; you don't need to do anything else. P.S. You might get a notification to link your GitHub account with WP.org when the pull request is merged so that you get contribution credit. |
This may be the source of the bug in #41260? |
@cbirdsong Yes, this bug has the same underlying cause. The Layout control is not really aware that it's editing layout for multiple blocks. It receives the
When you disable the "Allow to wrap" toggle, it changes the
Here
@Mamaduka This will be tough, because the current API behavior is seriously broken and there are many cases that are handled incorrectly. We can't keep it that way forever. If |
@jsnajdr, that's a good point. I doubt many are aware of the current What do you think of my proposal to create a separate issue for the general P.S. The |
Sure, we can create a new API to modify multiple blocks. This was a tradeoff we made when adding the capability to modify multiple blocks. Unfortunately all controls are nested within block edit functions. If we do something like Block API: try separate controls registration, it will also fix this problem, because we can just get all the controls for a block type. |
Maybe #41260 could be the "canonical" bug for this? It is more directly related to the The effects in the Embed block can be tidied up: currently
It seems to me only weakly related. It's used by the Gallery block to loop through the child blocks, Images, and set attributes on them. It's a shortcut for |
While it might be known already, sharing that this affects all embed blocks (Spotify, YouTube, etc.) and images wherever you drag them. Also, dragging them into a group or block with group-like behavior will have the same bug. |
Hey everyone 👋 I've just created a PR to address the embed block's side of the problem, as it shouldn't be calling Just to add another perspective on how to improve Here's a mini breakdown of the main (only?) use cases for Single block selected:
Multiple blocks selected of same block type e.g. Multiple Row blocks
Multiple blocks selected of different block types e.g. Paragraph block and a Heading block
In an ideal world
I may be missing more use cases, but if I'm not, that would fix all the bugs and not impact any other existing code, or require any blocks to change their behaviour. Just some thoughts 👍 |
Description
I have created blank theme with the Create Block Theme Plugin.
I have created a post and I added the following blocks structure:
Then I have selected the Heading, Paragraph, Image and Youtube blocks and dragged them outside their parent.
The image block got replaced by another instance of a youtube block, with the same video. Doesn't matter if I drag it one level upper or at root level.
Seems to happen only when an Image block is sibling of the youtube block. I can't replicate this behavior with the paragraph or heading blocks.
After dragging the blocks, and trying to press Undo I need to spam it multiple times till I get to the state before dragging the blocks. Doing single clicks to it doesn't work.
I also tried with the TT4 theme. And the exact same happens.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
gg.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: