Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix the My Jetpack app failing to load on WordPress installs without the Gutenberg plugin active, where the wp-theme script handle it depends on is otherwise unregistered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix the My Jetpack app failing to load on WordPress installs without the Gutenberg plugin active, where the wp-theme script handle it depends on is otherwise unregistered.
Fix the My Jetpack app failing to load on WordPress 6.9 installs without the Gutenberg plugin active, where the wp-theme script handle it depends on is otherwise unregistered.

3 changes: 2 additions & 1 deletion projects/packages/my-jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"automattic/jetpack-plans": "@dev",
"automattic/jetpack-status": "@dev",
"automattic/jetpack-sync": "@dev",
"automattic/jetpack-protect-status": "@dev"
"automattic/jetpack-protect-status": "@dev",
"automattic/jetpack-wp-build-polyfills": "@dev"
},
"require-dev": {
"yoast/phpunit-polyfills": "^4.0.0",
Expand Down
31 changes: 31 additions & 0 deletions projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Automattic\Jetpack\Sync\Functions as Sync_Functions;
use Automattic\Jetpack\Terms_Of_Service;
use Automattic\Jetpack\Tracking;
use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Polyfills;
use Jetpack;
use WP_Error;

Expand Down Expand Up @@ -247,12 +248,42 @@ public static function can_use_analytics() {
return $tracking->should_enable_tracking( new Terms_Of_Service(), $status );
}

/**
* Register polyfills for the wp-notices / wp-private-apis / wp-theme handles the
* My Jetpack app bundle depends on but WP < 7.0 does not ship (or ships with an
* incomplete allowlist) when the Gutenberg plugin is not active.
*
* Without this, `my_jetpack_main_app` is enqueued with an unregistered `wp-theme`
* dependency, so WP silently drops the script (no console error) and the My Jetpack
* app — plus any consumer that hard-depends on it, such as Jetpack Boost — renders
* a blank page. Only the handles the bundle actually uses are requested.
*
Comment on lines +252 to +255

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like AI over-explanation to me.

Suggested change
* Register polyfills for the wp-notices / wp-private-apis / wp-theme handles the
* My Jetpack app bundle depends on but WP < 7.0 does not ship (or ships with an
* incomplete allowlist) when the Gutenberg plugin is not active.
*
* Without this, `my_jetpack_main_app` is enqueued with an unregistered `wp-theme`
* dependency, so WP silently drops the script (no console error) and the My Jetpack
* app — plus any consumer that hard-depends on it, such as Jetpack Boost — renders
* a blank page. Only the handles the bundle actually uses are requested.
*
* Register polyfills for the wp-notices / wp-private-apis / wp-theme handles the
* My Jetpack app bundle depends on but WP < 7.0 does not ship (or ships with an
* incomplete allowlist).
*

* @return void
*/
public static function register_wp_build_polyfills() {
if ( ! class_exists( WP_Build_Polyfills::class ) ) {
return;
}

WP_Build_Polyfills::register(
'my-jetpack',
array( 'wp-notices', 'wp-private-apis', 'wp-theme' )
);
}

/**
* Enqueue admin page assets.
*
* @return void
*/
public static function enqueue_scripts() {
// Register the wp-build-polyfills shim before the extension hook below or
// the app script can enqueue against wp-theme / wp-private-apis / wp-notices.
// WP_Build_Polyfills registers synchronously on its first caller, so calling
// it after a hook consumer would leave our handles recorded but unregistered
// for this request.
self::register_wp_build_polyfills();

/**
* Fires after the My Jetpack page is initialized.
* Allows for enqueuing additional scripts only on the My Jetpack page.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Tests for Initializer::register_wp_build_polyfills().
*
* @package automattic/my-jetpack
*/

namespace Automattic\Jetpack\My_Jetpack;

use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Polyfills;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

/**
* Verifies My Jetpack requests the wp-build-polyfills shim for the script handles
* its app bundle depends on but older WordPress (< 7.0, no Gutenberg) does not ship.
*
* @see \Automattic\Jetpack\My_Jetpack\Initializer::register_wp_build_polyfills
*/
class Register_Wp_Build_Polyfills_Test extends TestCase {

/**
* The app bundle's polyfill-provided handles that must be requested.
*/
const EXPECTED_HANDLES = array( 'wp-notices', 'wp-private-apis', 'wp-theme' );

/**
* Reset the WP_Build_Polyfills static registrar so tests do not inherit state.
*/
public function tearDown(): void {
foreach ( array(
'requested' => array(),
'hooked' => false,
'wp_version_threshold' => '7.0',
) as $name => $value ) {
$prop = new ReflectionProperty( WP_Build_Polyfills::class, $name );
if ( PHP_VERSION_ID < 80100 ) {
$prop->setAccessible( true );
}
$prop->setValue( null, $value );
}
parent::tearDown();
}

/**
* Registering requests each required handle for the `my-jetpack` consumer.
*/
public function test_registers_required_polyfill_handles() {
Initializer::register_wp_build_polyfills();

$consumers = WP_Build_Polyfills::get_consumers();

foreach ( self::EXPECTED_HANDLES as $handle ) {
$this->assertArrayHasKey( $handle, $consumers, "$handle should be requested" );
$this->assertContains( 'my-jetpack', $consumers[ $handle ], "$handle should list the my-jetpack consumer" );
}
}

/**
* Guards against bundle drift: if a future `@wordpress/*` bump makes the app
* depend on another polyfill-covered handle (e.g. `wp-views`) that we do not
* request, that page would blank out with no console error. Fail here instead.
*
* Skips when the package has not been built (no asset file to inspect).
*/
public function test_requested_handles_cover_polyfilled_bundle_dependencies() {
$asset_file = dirname( __DIR__, 2 ) . '/build/index.asset.php';
if ( ! is_readable( $asset_file ) ) {
$this->markTestSkipped( 'my_jetpack_main_app build asset not found; run the package build first.' );
}

$asset = require $asset_file;
$deps = $asset['dependencies'] ?? array();
$polyfilled = array_values( array_intersect( $deps, WP_Build_Polyfills::SCRIPT_HANDLES ) );
$missing = array_values( array_diff( $polyfilled, self::EXPECTED_HANDLES ) );

$this->assertSame(
array(),
$missing,
'The app bundle depends on polyfill-covered handle(s) not requested by register_wp_build_polyfills(): ' . implode( ', ', $missing )
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Significance: patch
Type: changed
Comment: Update composer.lock.
3 changes: 2 additions & 1 deletion projects/plugins/backup/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix a blank Boost admin page on WordPress installs without the Gutenberg plugin active, where the wp-theme script handle the embedded My Jetpack app depends on was otherwise unregistered.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fix a blank Boost admin page on WordPress installs without the Gutenberg plugin active, where the wp-theme script handle the embedded My Jetpack app depends on was otherwise unregistered.
Fix a blank Boost admin page on WordPress 6.9 installs without the Gutenberg plugin active, where the wp-theme script handle the embedded My Jetpack app depends on was otherwise unregistered.

69 changes: 68 additions & 1 deletion projects/plugins/boost/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Significance: patch
Type: other
Comment: Update composer.lock.
3 changes: 2 additions & 1 deletion projects/plugins/jetpack/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Significance: patch
Type: changed
Comment: Update composer.lock.
69 changes: 68 additions & 1 deletion projects/plugins/protect/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Significance: patch
Type: changed
Comment: Update composer.lock.
Loading
Loading