Skip to content

Commit 016faff

Browse files
selulclaude
andcommitted
fix: load the block editor stylesheet inside the iframed editor canvas
WordPress 7.1 always renders the post editor in an iframe, and styles enqueued via enqueue_block_editor_assets only reach the parent document, leaving the visualizer/chart placeholder unstyled and breaking its e2e specs. Registering the stylesheet as the block type's editor_style gets it injected into the canvas on every core version. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 150d730 commit 016faff

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎classes/Visualizer/Gutenberg/Block.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,25 @@ public function enqueue_gutenberg_scripts() {
202202
* Hook server side rendering into render callback
203203
*/
204204
public function register_block_type() {
205+
$asset_path = VISUALIZER_ABSPATH . '/classes/Visualizer/Gutenberg/build/index.asset.php';
206+
$version = $this->version;
207+
if ( file_exists( $asset_path ) ) {
208+
// @phpstan-ignore-next-line
209+
$asset = require $asset_path;
210+
$version = isset( $asset['version'] ) ? $asset['version'] : $version;
211+
}
212+
if ( ! wp_style_is( 'visualizer-datatables', 'registered' ) ) {
213+
wp_register_style( 'visualizer-datatables', VISUALIZER_ABSURL . 'css/lib/datatables.min.css', array(), Visualizer_Plugin::VERSION );
214+
}
215+
if ( ! wp_style_is( 'visualizer-gutenberg-block', 'registered' ) ) {
216+
wp_register_style( 'visualizer-gutenberg-block', VISUALIZER_ABSURL . 'classes/Visualizer/Gutenberg/build/style-index.css', array( 'visualizer-datatables' ), $version );
217+
}
205218
register_block_type(
206219
'visualizer/chart', array(
220+
// The editor_style registration is what gets the stylesheet into the
221+
// iframed editor canvas; styles enqueued via enqueue_block_editor_assets
222+
// only reach the parent document.
223+
'editor_style' => 'visualizer-gutenberg-block',
207224
'render_callback' => array( $this, 'gutenberg_block_callback' ),
208225
'attributes' => array(
209226
'id' => array(

0 commit comments

Comments
 (0)