Closed joshuafredrickson closed 7 months ago
Will be a few days before I can look into this but it might be related to https://github.com/Log1x/acf-composer/blob/master/src/Block.php#L468-L477
With the cached blocks, we're utilizing render_template
instead – its possible it could be as easy as changing that from render_callback
but there might be more to it.
Awesome. I'll see if I look into this a bit further this week. Thanks!
I looked into this a bit and it is not related to render_callback
– it seems like the block gets rendered differently in the editor when registered with JSON but I'm not entirely sure where/what is doing it.
The easiest fix might be wrapping <innerBlocks />
with a div instead for the moment if it's an option.
Interesting.
Digging in a bit more, it looks like an upstream ACF issue. acf_block_version
for cached/json blocks is 2
and uncached is 1
.
Looks like this is assigned in advanced-custom-fields-pro/pro/blocks.php:acf_register_block_type
:
if (! isset($block['acf_block_version'])) {
$block['acf_block_version'] = 1;
}
To fix for now, I used the acf/register_block_type_args
filter:
add_filter('acf/register_block_type_args', function (array $block): array {
$block['acf_block_version'] = 2;
return $block;
});
~I'm still muddy as to why this is happening on ACF's end and what the reasoning is, but that's for another day I think.~
Sorry for the edits. I didn't end up saving it for another day.
Looking at this post, it lead me to add 'acf_block_version' => 2,
to the $settings
collection. This fixed the mismatch between cached and uncached blocks.
Whipping up a PR now for reference/proof of concept.
~I'm not 100% this is related to #230, but I have a feeling they might be in some way.~ Edit: It is not related.
I'm attempting to add classes to
InnerBlocks
like so:<InnerBlocks class="bg-gray-50 p-3" />
This works as expected when the blocks are cached via
acf:cache
:.block-editor-block-list__layout
has the additional classes assigned to it.However, when the blocks aren't cached (
acf:clear
), an additional wrapper is added (.block-editor-inner-blocks
) and no additional classes are added to.block-editor-block-list__layout
:I haven't jumped too deep into this yet, but I'm hoping you might have an idea of what be happening.
Thx!