Cannot insert blocks from Design Library
-
I’ve been using Spectra One with Spectra Gutenberg Blocks for a few months without major issues. Since a few days I cannot seem to use the Design Library anymore. I can open it, browse the blocks, but when I try to insert any of them in a standard page, the library closes and the block is not inserted. I am using WP 6.8.1 and the Spectra plugin v2.19.9 (latest).
I did a fair amount of debugging to figure out the issue, which was made much more difficult by the fact that the code that makes the design library work (
main.js, GitHub link) is minified and no unminified version is provided.The mentioned script calls the block editor core function
insertBlocksto insert the selected block, but this fails because the passedrootClientIdis always''. IninsertBlocksthere is acanInsertBlockType(block.name, rootClientId)check, which callsgetBlockEditingMode(rootClientId), which returnsfalsebecause the editing mode of the''client ID is set todisabledby the WP core componentDisableNonPageContentBlocks.I think the problem is that your code is trying to insert the block at the top level, but when using a FSE enabled theme like Spectra One, the top level contains element outside of the page content (e.g. header, title, footer), so that’s not allowed. This is confirmed by the fact that calling
wp.data.dispatch( 'core/block-editor' ).setBlockEditingMode('', 'contentOnly');in the browser console and then trying to inserting a block from the design library works fine; except that the block is inserted at the top level, not within the page content, which is wrong.In your
main.js, you are already calling the core functiongetInsertionPoint, but only to get the index at which to insert the block, discarding therootClientIdthat it returns. Using that client id to insert the block would solve the problem, I think (but I am just a dev—not a WP expert).I unfortunately don’t have an explanation for how I was able to use the design library just fine in the past. I tried also rolling back to a previous version of the plugin but it didn’t help.
The topic ‘Cannot insert blocks from Design Library’ is closed to new replies.