WordPress / gutenberg

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

"Convert to Blocks" fails if the block is not allowed by 'allowed_block_types_all' #66620

Open kyletcooper opened 2 days ago

kyletcooper commented 2 days ago

Description

Attempting to "Convert to Blocks" silently fails on installations if the chosen block for a section of HTML is not allowed by the theme/plugin.

I ran into this because of old posts that have paragraphs containing a single URL (I narrowed it down to this by deleting chunks of the content until I found this was the offending HTML). These can't be converted because the converter tries to turn them into a URL Embed block but can't because that block is filtered out out using allowed_block_types_all. I'd expect this to just go to the next best block (core/paragraph) if that block isn't available.

From a brief look I think this is happening in htmlToBlocks where getRawTransforms is possibly including transforms for disallowed blocks? I'm not very familiar with this area of WordPress so that might be incorrect.

Step-by-step reproduction instructions

  1. Disable the URL Embed block using allowed_block_types_all.
  2. Create a new post.
  3. Enter the Code Editor view.
  4. Paste <p>https://www.example.com/</p>.
  5. Return to Visual Editor view.
  6. Attempt to "Convert to Blocks" on the Classic Block this creates.
  7. Nothing happens.

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.

Please confirm which theme type you used for testing.

Mamaduka commented 2 days ago

Thanks for contributing, @kyletcooper!

The cause of the bug looks similar to or a duplicate of the following issues - #11245 and #27835.