Answer – When the post saves a version of the block, it saves it with the current custom post type blocks attrs as its own attrs. This locks the attrs from the custom post type to the regular post at that time.
A solution is to get the custom block type id and get the block, parse the attrs and use those.
find_block method taken from: Get specific Blocks from Post
public function find_blocks( array $blocks, string $type="custom_post/block" ) : array {
$matches = [];
foreach( $blocks as $block ) {
if( $block['blockName'] === $type )
$matches[] = $block;
if( count( $block['innerBlocks'] ) ) {
$matches = array_merge(
$matches,
find_blocks( $block['innerBlocks'], $type )
);
}
}
return $matches;
}
public function render_callback_dynamic (array $block_attributes, string $content) : string {
$attributes = (object) $block_attributes;
$customPostId = (int) property_exists($attributes, 'customPostId') ? $attributes->customPostId: 0;
if ($customPostId) {
$post = (object) get_post($customPostId);
$blocks = (array) $this->find_blocks(parse_blocks($post->post_content));
$block = (array) array_key_exists(0, $blocks) ? $blocks[0] : array();
$block_attributes = (array) array_key_exists('attrs', $block) ? $block['attrs'] : $block_attributes;
}
ob_start();
include 'blocks/template.php';
(string) $output = ob_get_clean();
if ( $output === '' ) {
$output = (string) $content;
}
return $output;
}