I have a custom Gutenberg Block created with Javascript & PHP which is missing its preview styles. The preview should look alike to the one you see in the editor behind it.
I have webpack that compiles all the styles for ALL the blocks into one single CSS file.
The block.json file is included via PHP:
register_block_type(
$directory . '/cover/block.json',
[ 'render_callback' => 'render_block_cover' ]
);
The styles file is included like follows:
...
add_action( 'wp_enqueue_scripts', [ $this, 'c_wp_enqueue_scripts' ], 100 );
add_action( 'enqueue_block_editor_assets', [ $this, 'c_wp_enqueue_scripts' ], 100 );
...
function c_wp_enqueue_scripts() {
...
$file_with_path_css = apply_filters( 'get_file_from_dist', 'index.css', true );
wp_enqueue_style( 'my-styles', $file_with_path_css, '', $theme->Version, 'all' );
}
I wonder if the styles have to be included via the reference in block.json. However with Wordpress 5.9 in earlier projects with a similar structure, the preview did actually work.
However those blocks were not registered in PHP, just in Javascript.
Q: What might the cause be, that the preview does not show any styles?
What I can exclude is, that it is a CSS hierarchical mistake. No styles seem to work, even if they are directly on the block without a parent.
