-
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
'core/list' with 'core/list-items' not loading correctly as innerblocks #61578
Comments
Thanks for reporting the issue, @Dotfly-fwiegand! Could you share a code example for the I see that the shared example uses the |
Hi, |
Hi, I can confirm that this is still relevant for at least WordPress 6.4 and above. All you need to reproduce this issue is to have a custom block that:
Then, while on the block editor, the steps to reproduce are:
(EDIT: the following proposed workaround doesn't actually work)
import { useBlockProps, useInnerBlockProps } from '@wordpress/block-editor';
export default function Edit( {attributes, setAttributes}) {
const ALLOWED_BLOCKS = [ 'core/list', 'core/list-item' ];
const LIST_TEMPLATE = [
['core/list', {},
[
['core/list-item', {placeholder: "add entry"}],
['core/list-item', {placeholder: "add entry"}]
]
],
];
const { children, ...blockProps } = useInnerBlockProps(
useBlockProps(),
{
allowedBlocks: ALLOWED_BLOCKS,
template: LIST_TEMPLATE,
templateLock: attributes.templateLock
}
)
return (
<>
<div { ...blockProps }>
<div className="wp-block-dotfly-takeaway__list e-link">
{ children }
</div>
</div>
</>
)
} |
Hi, I've spent some more time with this issue and realized that my previously mentioned workaround doesn't really work. Not sure what led me to that mistake. Sorry for the confusion. I've tested with WordPress 6.0, 6.1, 6.2, 6.3, 6.4 and 6.5, and all showed the same behavior, even with 6.0 where you actually need to manually set the A workaround that actually worked for me was to first check if the block currently has any inner blocks, and if it does, I won't pass the block template to the Once again, based on the issue description, here is an example of what worked for me: import { useSelect } from "@wordpress/data";
import { useBlockProps, useInnerBlockProps } from '@wordpress/block-editor';
export default function Edit( {clientId, attributes, setAttributes}) {
const ALLOWED_BLOCKS = [ 'core/list', 'core/list-item' ];
const LIST_TEMPLATE = [
['core/list', {},
[
['core/list-item', {placeholder: "add entry"}],
['core/list-item', {placeholder: "add entry"}]
]
],
];
const hasInnerBlocks = useSelect(
select => select( 'core/block-editor' ).getBlocks( clientId ).length > 0,
[]
);
const { children, ...blockProps } = useInnerBlockProps(
useBlockProps(),
{
allowedBlocks: ALLOWED_BLOCKS,
template: hasInnerBlocks ? null : LIST_TEMPLATE,
templateLock: attributes.templateLock
}
)
return (
<>
<div { ...blockProps }>
<div className="wp-block-dotfly-takeaway__list e-link">
{ children }
</div>
</div>
</>
)
} |
I can confirm this behavour. It's a severe problem for us. Any updates on that? |
Description
While creating Custom Blocks for our client, we came across this unexpected behaviour.
A Block with a list as innerblocks is only loading the content of the list-items which have a entry in the list_template.
To Clarify, if we create this list template:
and the editor adds more list-items, only the content of the first 2 is loaded after editor-reload, even though everything is saved to the database correctly. That leads to overwriting the desired list-items after the editor is reloaded without the correct content.
For Example:
Save 4 list-items -> reload page, only 2 are loaded correctly -> safe again and the other 2 get deleted, overwritten
This behaviour only occurred with list/list-items. We used the same code with different behaviour on "core/buttons" "core/button" and other core blocks.
Step-by-step reproduction instructions
Create a new Block with this edit JS
Build Plugin,
Screenshots, screen recording, code snippet
No response
Environment info
Tested in different environments (Docker / Orbstack, Debian Server) with Wordpress 6.5.3 and different Browsers (Arc, Chrome, Firefox, Safari). Tested with a clean installation without any other plugins active
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
The text was updated successfully, but these errors were encountered: