In the stories editor, there when a block is a selected, a context menu icon appears in the toolbar that looks like this.

If a CTA block is selected and the duplicate block is selected, the browser becomes unresponsive and sometimes crashes.
There might be some infinite loop, perhaps caused by some faulty React hook somewhere.
Block should fail to duplicate or at least a warning about duplicate CTA blocks is shown.

If the browser doesn't crash, then two CTA blocks are shown.
When either a CTA or a Page Attachment block is present on a Page, enforcing the block to be the last block on the Page is triggered. If there are more than one CTA / Page Attachment blocks then this causes the logic to be triggered infinitely since only one block can be the last block:
https://github.com/ampproject/amp-wp/blob/744b640f069c43bca209ad2bf988b105e345a8d4/assets/src/stories-editor/blocks/amp-story-page/edit.js#L145-L166
If more than one CTA/Page Attachment blocks are detected then before enforcing the block to be the last, two things should happen:
We could add an additional condition to the same useEffect hook that enforces the CTA/Attachment block to be the last, to only run if there is only one CTA or one Page Attachment block. Additionally, we can add another useEffect which removes the extra block(s) if detected which can also display a snackbar notice saying that the block was removed since each Page can have only 1 CTA block or 1 Attachment block.
https://www.youtube.com/watch?v=iItTJkcF7Qg&feature=youtu.be
There has already been a lot of work done on context menu for right click. See

Barring the edit as html option in this context menu, the options found in the right click context menu are much more useful. I would recommend removing the built in context menu and removing this the same menu found when right clicking.
This would require following.
edit as html added to the right click context menu. Related: https://github.com/ampproject/amp-wp/pull/3417 https://github.com/ampproject/amp-wp/issues/3466
The keyboard shortcut CTRL+Shift+D also has the same effect.
There seems to be some infinite loop somewhere causing that crash:

I would recommend removing the built in context menu and removing this the same menu found when right clicking.
Let's create a separate issue to discuss that.
Looking into this.
I'm adding another AC:
Haven't looked into the code yet but we have a logic in place that is trying to set the CTA block to be the last on a Page -- if there would be two CTA blocks then that most likely would cause infinite updating. Having 2 CTA blocks shouldn't be allowed anyway, however, warning instead of crashing and/or removing the extra CTA block if this should happen for some reason would be good, too.
That sounds like a plausible cause 馃憤
Preventing wherever possible makes sense, though we cannot remove the keyboard shortcut or the option from the menu at the moment.
Ah, okay, thought that it's the context menu but it's happening in case of the default More Options Menu, and that can't be removed.
I guess the same should go for the Page Attachment block as well then -- that also triggers the enforcing being the last block logic.
Any objections to adding Page Attachment to this issue as well since it's basically the same issue?
Any objections to adding Page Attachment to this issue as well since it's basically the same issue?
works for me 馃憤
To confirm with UX:
Should we display a snack-bar notice when the forbidden block gets removed?
Otherwise IB ready.
Updated the IB to add the snack-bar notification. Ready for review now.
I think this speaks into the larger issue of customising the "More Options" menu (the Gutenberg term is BlockSettingsMenu).
There are some checks for some of these things we want to do (the component has a canDuplicate flag), but we can't easily manipulate it and there are no filters readily available.
Should we (rather than fix this single issue only) look into either:
BlockSettingsMenu with our own menu as we have done for other elements (e.g. the media inserter)?BlockSettingsMenu upstream to allow the level of customization that we need?Or maybe even both, as the latter has a longer turn-around.
Note: We also want to add custom menu items, but that's already possible through the BlockSettingsMenuPluginsExtension, however of course with limited ability for customization here as well in terms of ordering, UI, etc.
Should we (rather than fix this single issue only) look into either:
It might make sense fixing this issue first as a bugfix and additionally create a follow-up issue for looking into generally replacing the BlockSettingsMenu or updating it upstream. It'll probably take enough time not to make it to 1.4 otherwise.
Thoughts?
I looked into customizing those components in https://github.com/ampproject/amp-wp/issues/3504#issuecomment-544566566, where it seems like replacing those is not easily possible. Upstream contributions might be possible, but it's unsure whether these would be (a) accepted and (b) implemented in time.
It's one of the many symptoms of the reliance on Gutenberg. As discussed in today's meeting, I am planning on writing a more detailed design doc based on #2554 to plan a bigger technical overhaul of the stories editor. This would reduce the strong dependency on Gutenberg to gain more control over the whole editor UI.
I spent a fair bit of time looking at change or removing the BlockSettingsMenu and couldn't find a way. There is no other hacky way to do it either, as they are no solid css classes to hide it. The menu is also conditional, so way to easily remove it.
I have said before, I believe the context menu that is shown when right clicking should be shown here, when a block is selected. It would keep the two menus in line and make it easier to find the right click options via screen readers etc.
I agree with above statements that we should fix the root issue, as they maybe other ways we haven't thought of yet to copy CTA / attachment blocks.
Note that considering the RC this Friday and release next week then that's not a valid option right now. We can "fix" the bug for the release and look into the root issue separately since that will need some planning and will take quite some time to figure out a general best solution + implement it.
Probably would be good to continue the discussion in a separate dedicated issue outside of this bugfix issue.
Agree with both of you. Hence the planned design doc in #2554 to evaluate how we can fix the root issue.
Was unable to duplicate, but the message that appears is:
"1 block removed. Only one block of this type is allowed per page"
There wasn't a block removed
I think that this issue is related to https://github.com/WordPress/gutenberg/issues/14515 . If the allow blocks could be change dynamically then the duplicate block would never appear.
If we fix this upstream, it would be useful considering these lines of code
Issue was erroneously closed automatically before completing. Reopening.
Verified in QA