I was able to prevent the unwanted altering of HTML by using the render_block_core/group
filter, and a copy of wp_restore_group_inner_container, without the JSON support check.
public static function my_add_block_group_inner( $block_content, $block ) {
$tag_name = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div';
$group_with_inner_container_regex = sprintf(
'/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',
preg_quote( $tag_name, "https://wordpress.stackexchange.com/" )
);
$replace_regex = sprintf(
'/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms',
preg_quote( $tag_name, "https://wordpress.stackexchange.com/" )
);
$updated_content = preg_replace_callback(
$replace_regex,
static function( $matches ) {
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];
},
$block_content
);
return $updated_content;
}
add_filter( 'render_block_core/group', 'my_add_block_group_inner' );