WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.33k stars 4.12k forks source link

Auto p corrupting paragraph blocks. #64353

Open nbcsteveb opened 1 month ago

nbcsteveb commented 1 month ago

Description

If I save an article such as:

wp_insert_post(['post_content'=>'<!-- wp:paragraph --><p dir="ltr">Hello, world!</p><! -- /wp:paragraph -->']);

When you open the article and save as draft, this function (or something around it) is updating this content to:

<!-- wp:paragraph -->
<p><p dir="ltr">Hello, world!</p></p>
<!-- /wp:paragraph -->

Which Gutenberg then tells the user is an invalid block of content:

image

And when resolving:

image

Step-by-step reproduction instructions

  1. Save article: wp_insert_post(['post_content'=>'<!-- wp:paragraph --><p dir="ltr">Hello, world!</p><! -- /wp:paragraph -->']);
  2. Open article in WP and save as draft.
  3. Refresh the page.
  4. Notice the warning about invalid content.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

talldan commented 1 month ago

I wasn't able to reproduce the exact same issue. For me, the block is show as invalid straight away (step 2) and I don't see extra paragraphs. It might be a difference in configuration. I don't think the paragraph knows how to handle the dir attribute, so that's why I get a validation issue.

If I use markup that I created in the editor using the 'Language' format I'm not seeing any issues:

wp_insert_post( array( 'post_content' => '<!-- wp:paragraph --><p><bdo lang="" dir="ltr">Hello, world!</bdo></p><!-- /wp:paragraph -->' ) );
miminari commented 1 month ago

I also tested on WordPress 6.6.1, and it wasn't reproduced. Likewise, I could not proceed to Step 2.

At the same time, I tried the suggested code adding lang attribute and it worked fine.

wp_insert_post( array( 'post_content' => '<!-- wp:paragraph --><p><bdo lang="" dir="ltr">Hello, world!</bdo></p><!-- /wp:paragraph -->' ) );

SS_2024-08-14 9 51 38

Some assumptions might be different, but I wasn't able to reproduce too.

github-actions[bot] commented 1 week ago

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.