Skip to content

Commit

Permalink
Blaze: only enqueue script in post editor
Browse files Browse the repository at this point in the history
Fixes #28184

1. We do not need Blaze in the site editor, since we cannot promote specific posts from there.
2. The Blaze panel relies on @wordpress/editor, which we cannot use in the site editor or the widget editor.
3. When we enqueue the Blaze panel in the site editor or the widget editor, we run into this issue: #20357. This causes Fatal errors just like the one we experienced and worked around in #21763.

To solve this issue, we switch to using the admin_enqueue_scripts hook to decide whether when to enqueue our script. It allows us to conditionally enqueue the file based on the page we're on, which is something the enqueue_block_editor_assets hook does not allow yet.
  • Loading branch information
jeherve committed Jan 5, 2023
1 parent f4890f9 commit fd29b2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions projects/packages/blaze/changelog/fix-fatal-site-editor-blaze
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Do not load the Blaze panel in the site editor or the widget editor.
15 changes: 13 additions & 2 deletions projects/packages/blaze/src/class-blaze.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function register() {
if ( ! did_action( 'jetpack_on_blaze_init' ) ) {
if ( self::should_initialize() ) {
add_filter( 'post_row_actions', array( $this, 'jetpack_blaze_row_action' ), 10, 2 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_block_editor_assets' ) );
}

/**
Expand Down Expand Up @@ -133,8 +133,19 @@ public function jetpack_blaze_row_action( $post_actions, $post ) {

/**
* Enqueue block editor assets.
*
* @param string $hook The current admin page.
*/
public function enqueue_block_editor_assets() {
public function enqueue_block_editor_assets( $hook ) {
/*
* We do not want (nor need) Blaze in the site editor or the widget editor, only in the post editor.
* Enqueueing the script in those editors would cause a fatal error.
* See #20357 for more info.
*/
if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) {
return;
}

Assets::register_script(
'jetpack-promote-editor',
'../build/editor.js',
Expand Down

0 comments on commit fd29b2e

Please sign in to comment.