-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widgets screen: getBlocks() doesn't return innerBlocks #32607
Comments
Hey @tomusborne. This is an unfortunate side effect of how widget areas are implemented. Each widget area is a block that connects its I'd like us to revisit the architecture of this after 5.8 (I think that Widget Area possibly shouldn't be a block) but for now a workaround is to use something like: const widgetAreas = wp.data.select( 'core' ).getWidgetAreas();
const firstWidgetAreasBlocks = wp.data.select( 'core' ).getEditedEntityRecord( 'root', 'postType', `widget-area-${ widgetAreas[0].id }` ).blocks; |
@noisysocks Thanks for letting me know. Really appreciate the workaround as well, I'll play around with it. |
@noisysocks tried your code suggestion, however returned |
The issue seems to be that the The block editor store does actually have all the data needed, but it's not exposed by the An alternative workaround would be something like: const widgetAreas = wp.data.select('core/block-editor').getBlocks();
const blocks = widgetAreas.map( ( widgetArea ) => {
const innerBlocks = wp.data.select('core/block-editor').getBlocks( widgetArea.clientId );
return {
...widgetArea,
innerBlocks
};
} ); |
I'll close this as it's a quirk of how widget areas are implemented and there's no "bug" per se. It's definitely an argument against using blocks to implement widget areas, though, which I'll note in #33254. |
Description
When on the Widget screen, using
wp.data.select( 'core/block-editor' ).getBlocks()
only returns the top-level widget areas.innerBlocks
is an empty array even when inner blocks (widgets) exist.Step-by-step reproduction instructions
wp.data.select( 'core/block-editor' ).getBlocks()
Expected behaviour
I expect the
innerBlocks
to be available like they are in the editor: https://www.screencast.com/t/o9LFmZv8ElActual behaviour
innerBlocks
is empty even though there are widgets inside the area: https://www.screencast.com/t/WZgm8RXGvWordPress information
Device information
The text was updated successfully, but these errors were encountered: