Skip to content

Commit

Permalink
Block editor: Hotfix performance regression (#41309)
Browse files Browse the repository at this point in the history
* Block editor: Hotfix performance regression

* Regenerate files

* Fix path

* Bail when running a local dev build of Gutenberg

* Simplify file path

* Add Gutenberg stubs

* Update Jetpack Phan config with Gutenberg stubs

* Load Gutenberg stubs

* Rename function and update docblock

* Don't hotfix if blocks module is not active

* Fix version in docblock

* Revert changes in the Jetpack plugin

* Remove Jetpack changelog

* Revert Phan changes for the Jetpack plugin

* Move hotfix to jetpack-mu-wpcom

* Revert automated linter changes

* Fix Phan errors

* Remove Phan suppression

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13051029268

Upstream-Ref: Automattic/jetpack@40d66c6
  • Loading branch information
mmtr authored and matticbot committed Jan 30, 2025
1 parent 4d3fd04 commit 592c931
Show file tree
Hide file tree
Showing 6 changed files with 687 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This is an alpha version! The changes listed here are not final.
- Adds verify email task to newsletter goal launchpad
- Admin Bar: Point the Edit Site menu item to /site-editor.php
- Always loads Odyssey Stats widget regardless of wpcom_admin_interface
- Block editor: Hotfix performance regression
- Changed the experiment cache key so that users get assigned once the experiment starts.
- Code: Use function-style exit() and die() with a default status code of 0.
- Coming Soon: Add more checks to the ETK version comparison.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function add_default_editor_styles_for_classic_themes( $editor_settings,
return $editor_settings;
}

$default_editor_styles_file = gutenberg_dir_path() . 'build/block-editor/default-editor-styles.css'; // @phan-suppress-current-line PhanUndeclaredFunction
$default_editor_styles_file = gutenberg_dir_path() . 'build/block-editor/default-editor-styles.css';
if ( ! file_exists( $default_editor_styles_file ) ) {
return $editor_settings;
}
Expand Down
214 changes: 214 additions & 0 deletions src/features/wpcom-hotfixes/wp-block-editor-19.9.0-hotfix.min.js

Large diffs are not rendered by default.

211 changes: 211 additions & 0 deletions src/features/wpcom-hotfixes/wp-block-editor-20.0.0-hotfix.min.js

Large diffs are not rendered by default.

224 changes: 224 additions & 0 deletions src/features/wpcom-hotfixes/wp-block-editor-20.1.0-hotfix.min.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/features/wpcom-hotfixes/wpcom-hotfixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,39 @@ function ( $content ) {
1
);
}

/**
* Overrides the `wp-block-editor` script with a hotfix to prevent a performance issue present in
* Gutenberg v19.0, v20.0, and v20.1 (see https://github.com/WordPress/gutenberg/issues/68875).
*
* Our custom script has been generated by applying the fix introduced in Gutenberg v20.2
* (see https://github.com/WordPress/gutenberg/pull/68898) in a local Gutenberg environment and
* running `npm run build` to extract the fixed `wp-block-editor` script.
*
* @param WP_Scripts $scripts WP_Scripts instance.
*/
function wpcom_fix_performance_issue_block_editor_v19_9_v20_0_v20_1( $scripts ) {
if ( ! defined( 'GUTENBERG_VERSION' ) ) {
return;
}

if ( ! in_array( GUTENBERG_VERSION, array( '19.9.0', '20.0.0', '20.1.0' ), true ) ) {
return;
}

$path = gutenberg_dir_path() . 'build/block-editor/index.min.js';
$handle = 'wp-block-editor';
$asset_file = substr( $path, 0, - ( strlen( '.js' ) ) ) . '.asset.php';
$asset = file_exists( $asset_file ) ? require $asset_file : null;
$dependencies = $asset['dependencies'] ?? array();
$version = $asset['version'] ?? GUTENBERG_VERSION;
gutenberg_override_script(
$scripts,
$handle,
plugins_url( 'wp-block-editor-' . GUTENBERG_VERSION . '-hotfix.min.js', __FILE__ ),
$dependencies,
$version,
true
);
}
add_action( 'wp_default_scripts', 'wpcom_fix_performance_issue_block_editor_v19_9_v20_0_v20_1', 11 );

0 comments on commit 592c931

Please sign in to comment.