-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Close block settings menu after removing block #15543
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work on this ❤️.
I thought I'd review as I'd seen this bug mentioned in a design triage, but then I couldn't find the comments related to the triage on the original issue. It turns out there's a separate issue from the accessibility audit - #15313
I know it broadens the scope a bit, but it'd be great to address this for each of the menu items, as mentioned on that issue.
packages/block-editor/src/components/block-settings-menu/index.js
Outdated
Show resolved
Hide resolved
I don't think it should block this PR. |
Since it was a rather easy fix, I've made that change now as well. The only case where the settings menu is not closed is when the action (i.e. "Insert After") is performed via a keyboard shortcut. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quickly tested and seems to me there's an issue with the Undo/Redo history. To reproduce:
- add a paragraph block with some text
- remove it via the More menu in the top bar
- click Undo
- at this point, the default block appears: expected the paragraph should be restored
- regardless, the "More" button is rendered in the top bar
- click the "More" button: the editor crashes displaying the "Attempt Recovery" dialog
Repeat the steps above, but this time click Undo twice:
- the deleted paragraph is restored
- the "More" button is rendered in the top bar
- same result: click the "More" button and the editor crashes
Thanks for testing, @afercia! I can reproduce this issue.
I think the issue here is that So |
ea26477 should fix the issue of the More menu being shown in that case, while not re-introducing the side effect originally mentioned in #15543 (comment). As for the undo/redo history, the issue seems kinda logical. For comparison, here's how it works on a fresh post:
With this PR here, the following happens:
It works correctly when there are multiple paragraph blocks:
tl;dr the undo/history works as expected, at least from a technical perspective. However, as a user it indeed seems odd that it would require two undo actions to get back the previous block. I cannot think of a good solution for that off the top of my head. But it should probably be looked at in a separate PR. |
Yep this was also previously noted for a similar issue when pressing Enter at the beginning of a block. Will create a separate issue with details. Edit: created #15610 |
Awesome, thanks! @talldan Would you mind reviewing this again? |
This was also discussed in #14754 . In fact, perhaps not here, but I suggest we'd go one step further and handle From #14754 (comment) :
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay, I haven't tested and I have a few comments that could be addressed.
packages/block-editor/src/components/block-settings-menu/index.js
Outdated
Show resolved
Hide resolved
Also fixes the problem for me. Before I would get an error thrown when removing the initial block. With this PR, no error is raised. |
It's curious to me that an
Yes. Would you mind to create an issue to track this? |
Aside: If I understand correctly, this "fix" is not related to the original scope of the pull request. It would have simplified review if it had been proposed as its own pull request. |
In my testing, the error occurs here: gutenberg/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-group.js Line 15 in 8960509
Because gutenberg/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-group.js Line 29 in 8960509
Part of this comes down to: We don't prescribe an expected behavior of The proposed condition of gutenberg/packages/block-editor/src/store/selectors.js Lines 119 to 122 in 8960509
This is a pretty loose guarantee, though. For example, hypothetically I imagine an error could still occur if a multi-selection of blocks included a client ID which did not exist, in the rendering of gutenberg/packages/block-editor/src/components/block-toolbar/index.js Lines 20 to 27 in 8960509
|
I disagree about the "not related to the original scope" part. This PR was intended to fix #15458 (editor crash) and coincidentally also fixes #15313. Without this fix the PR would be incomplete as the editor crashes still in the following scenario:
You'll get this:
Thanks for the detailed breakdown after that. Is this something we can address in a separate issue/PR or would you prefer it to be handled here? Since you said:
I'm asking because I want to get the workflows right here in this project. At the same time, I'd also love to see this fixed rather sooner than later, as this error occurs frequently in our user testing 🙂 |
The changes here include a different behavior that I don't believe should be expected: In I'm not sure it helps with the issues for "Undo", but I've discovered the underlying cause to the original issues reported in #15458:
In 2f1a82f, I add a condition to only select the previous block if one exists. Could you check to see if the I have some local changes to include an end-to-end test to verify against this regression, but I see another (unrelated) error which occurs here, which we may want to address separately instead. It is an error caused by To the question of process: I understand the urgency of having the user-facing issue resolved. My concern is that urgency is lost as soon as the symptom is treated. If the underlying issue is left to remain, it will inevitably manifest itself again in the future (or in the present by some yet-to-be-discovered circumstances). |
Thanks a ton @aduth! I can confirm that with this change the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for bearing with me. Looks good to me.
Per my previous comment, I'll follow-up with an end-to-end test case which includes a fix for the unrelated issue with ensureDefaultBlock
.
Pull request at #15786 (currently cherry-picks the commit from this branch). |
Description
Fixes #15458 by closing the block settings menu after removing a block through that menu.
Also fixes #15313.
This prevents editor crashes when there are no more blocks left but the block settings menu is still rendered as it's open.
How has this been tested?
Following the steps outlined in #15458 I did this:
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: