gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Console error when group templateLock = contentOnly on trying to add item to list

Open bvlgn opened this issue 3 years ago • 6 comments

Description

Tested with WordPress 6.2 beta 3.

When a group has templateLock = contentOnly then it is not possible to add extra items. If you try to you will fail and an Uncaught Type error shows in the console. See screen recording.

I would expect to be able to add list items and not to cause a console error.

Step-by-step reproduction instructions

On a new page, go to code editor and paste the following markup:

<!-- wp:group {"templateLock":"contentOnly","layout":{"type":"constrained"}} -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>These paragraphs and the list block is part of a group which has a templateLock of 'contentOnly'.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you try to add an extra list item this will fail and an error is shown in the console.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>One</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Two</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list --></div>
<!-- /wp:group -->

Make sure the console is showing.

Try to add an item to the list. This will fail and an error will show in the console. See screenrecording.

Screenshots, screen recording, code snippet

listbug

Environment info

WordPress 6.2 beta 3 Chrome browser

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

bvlgn avatar Feb 22 '23 15:02 bvlgn

@BennyVL

Thanks for the report.

I think the inability to add new list items is expected behavior. This is because list items are blocks, and contentOnly prohibits the addition of blocks. Ideally, when the enter key is pressed, the line should break within that list item.

t-hamano avatar Feb 27 '23 23:02 t-hamano

But when the enter key is pressed you get the console error, which is the actual bug I tried to report (and the line doesn't break).

You are right that because of contentOnly the addition of list item blocks is prohibited and is as expected from the system perspective. I think end users though wouldn't expect that. They will likely expect that adding list items is adding content only. But maybe that is something that could/should be discussed at a more broader level elsewhere?

bvlgn avatar Feb 28 '23 11:02 bvlgn

But when the enter key is pressed you get the console error, which is the actual bug I tried to report (and the line doesn't break).

Yes, I too think this should be fixed.

Perhaps it would be better to discuss in another issue whether pressing Enter breaks the line or creates a new list item.

t-hamano avatar Feb 28 '23 11:02 t-hamano

Shouldn't this issue be added to the WordPress 6.2 Editor Tasks? After all it's a regression bug, the error doesn't occur in WP 6.1.

bvlgn avatar Feb 28 '23 11:02 bvlgn

I got the same result for WordPress 6.1, 6.1.1, and 6.2 Beta3. When I press the enter key on a list item, nothing happens and an error is displayed in the browser console. Am I missing something?

t-hamano avatar Mar 01 '23 12:03 t-hamano

Sorry for the confusion, I re-tested this with 6.1 and 6.1.1 and you are right, the bug was already present in those version too.

bvlgn avatar Mar 01 '23 12:03 bvlgn