From 648707a46209e0843779149910de1fc2458292e1 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Wed, 9 Aug 2023 09:31:15 +0200 Subject: [PATCH 1/5] Revert "Performance: Cache script data in a transient for production builds" (#10509) * Revert "Performance: Cache script data in a transient for production builds (#9120)" This reverts commit 6b9955d2a51bc56b0b029edc521ff98e3403dffc. * fix WordPress version * fix version --- .wp-env.json | 2 +- src/Assets/Api.php | 104 ++++++++++----------------------------------- 2 files changed, 23 insertions(+), 83 deletions(-) diff --git a/.wp-env.json b/.wp-env.json index 024d487e93d..14c1c790faa 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -1,5 +1,5 @@ { - "core": null, + "core": "WordPress/WordPress#6.2.2", "plugins": [ "https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip", "https://github.com/WP-API/Basic-Auth/archive/master.zip", diff --git a/src/Assets/Api.php b/src/Assets/Api.php index 9550be10897..3fdcd70007e 100644 --- a/src/Assets/Api.php +++ b/src/Assets/Api.php @@ -18,20 +18,6 @@ class Api { */ private $inline_scripts = []; - /** - * Determines if caching is enabled for script data. - * - * @var boolean - */ - private $disable_cache = false; - - /** - * Stores loaded script data for the current request - * - * @var array|null - */ - private $script_data = null; - /** * Reference to the Package instance * @@ -45,9 +31,7 @@ class Api { * @param Package $package An instance of Package. */ public function __construct( Package $package ) { - $this->package = $package; - $this->disable_cache = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ! $this->package->feature()->is_production_environment(); - add_action( 'shutdown', array( $this, 'update_script_data_cache' ), 20 ); + $this->package = $package; } /** @@ -92,44 +76,6 @@ public function get_block_metadata_path( $block_name, $path = '' ) { return $path_to_metadata_from_plugin_root; } - /** - * Initialize and load cached script data from the transient cache. - * - * @return array - */ - private function get_cached_script_data() { - if ( $this->disable_cache ) { - return []; - } - - $transient_value = json_decode( (string) get_transient( 'woocommerce_blocks_asset_api_script_data' ), true ); - - if ( empty( $transient_value ) || empty( $transient_value['script_data'] ) || empty( $transient_value['version'] ) || $transient_value['version'] !== $this->package->get_version() ) { - return []; - } - - return (array) ( $transient_value['script_data'] ?? [] ); - } - - /** - * Store all cached script data in the transient cache. - */ - public function update_script_data_cache() { - if ( is_null( $this->script_data ) || $this->disable_cache ) { - return; - } - set_transient( - 'woocommerce_blocks_asset_api_script_data', - wp_json_encode( - array( - 'script_data' => $this->script_data, - 'version' => $this->package->get_version(), - ) - ), - DAY_IN_SECONDS * 30 - ); - } - /** * Get src, version and dependencies given a script relative src. * @@ -139,37 +85,31 @@ public function update_script_data_cache() { * @return array src, version and dependencies of the script. */ public function get_script_data( $relative_src, $dependencies = [] ) { - if ( ! $relative_src ) { - return array( - 'src' => '', - 'version' => '1', - 'dependencies' => $dependencies, - ); - } - - if ( is_null( $this->script_data ) ) { - $this->script_data = $this->get_cached_script_data(); - } - - if ( empty( $this->script_data[ $relative_src ] ) ) { - $asset_path = $this->package->get_path( str_replace( '.js', '.asset.php', $relative_src ) ); - // The following require is safe because we are checking if the file exists and it is not a user input. - // nosemgrep audit.php.lang.security.file.inclusion-arg. - $asset = file_exists( $asset_path ) ? require $asset_path : []; + $src = ''; + $version = '1'; - $this->script_data[ $relative_src ] = array( - 'src' => $this->get_asset_url( $relative_src ), - 'version' => ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ), - 'dependencies' => ! empty( $asset['dependencies'] ) ? $asset['dependencies'] : [], + if ( $relative_src ) { + $src = $this->get_asset_url( $relative_src ); + $asset_path = $this->package->get_path( + str_replace( '.js', '.asset.php', $relative_src ) ); + + if ( file_exists( $asset_path ) ) { + // The following require is safe because we are checking if the file exists and it is not a user input. + // nosemgrep audit.php.lang.security.file.inclusion-arg. + $asset = require $asset_path; + $dependencies = isset( $asset['dependencies'] ) ? array_merge( $asset['dependencies'], $dependencies ) : $dependencies; + $version = ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src ); + } else { + $version = $this->get_file_version( $relative_src ); + } } - // Return asset details as well as the requested dependencies array. - return [ - 'src' => $this->script_data[ $relative_src ]['src'], - 'version' => $this->script_data[ $relative_src ]['version'], - 'dependencies' => array_merge( $this->script_data[ $relative_src ]['dependencies'], $dependencies ), - ]; + return array( + 'src' => $src, + 'version' => $version, + 'dependencies' => $dependencies, + ); } /** From 13eecbebae50a2bc0fcf55a9d6a72ab4d693ad9b Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 9 Aug 2023 09:37:45 +0200 Subject: [PATCH 2/5] update version to 10.6.5 --- composer.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- readme.txt | 2 +- src/Package.php | 2 +- woocommerce-gutenberg-products-block.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 6bd56abb82f..3144e715c1f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://woocommerce.com/", "type": "wordpress-plugin", - "version": "10.6.4", + "version": "10.6.5", "keywords": [ "gutenberg", "woocommerce", diff --git a/package-lock.json b/package-lock.json index 7ea83fc2d3d..4d3724a21fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@woocommerce/block-library", - "version": "10.6.4", + "version": "10.6.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@woocommerce/block-library", - "version": "10.6.4", + "version": "10.6.5", "hasInstallScript": true, "license": "GPL-3.0+", "dependencies": { diff --git a/package.json b/package.json index f9c37e77692..24d4d34b8ee 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "10.6.4", + "version": "10.6.5", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ diff --git a/readme.txt b/readme.txt index 0d5019e0682..29fb218b2fb 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks Requires at least: 6.2 Tested up to: 6.2 Requires PHP: 7.3 -Stable tag: 10.6.4 +Stable tag: 10.6.5 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/src/Package.php b/src/Package.php index 05efb353e9f..608921d7115 100644 --- a/src/Package.php +++ b/src/Package.php @@ -109,7 +109,7 @@ public static function container( $reset = false ) { NewPackage::class, function ( $container ) { // leave for automated version bumping. - $version = '10.6.4'; + $version = '10.6.5'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php index 87eda68b6ca..6b5e3a4fab6 100644 --- a/woocommerce-gutenberg-products-block.php +++ b/woocommerce-gutenberg-products-block.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Blocks * Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block * Description: WooCommerce blocks for the Gutenberg editor. - * Version: 10.6.4 + * Version: 10.6.5 * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block From e4b99979c3d01938ea0ef8c2add191980b4868b2 Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 9 Aug 2023 09:42:23 +0200 Subject: [PATCH 3/5] update changelog and testing instructions --- docs/internal-developers/testing/releases/1065.md | 10 ++++++++++ docs/internal-developers/testing/releases/README.md | 1 + readme.txt | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 docs/internal-developers/testing/releases/1065.md diff --git a/docs/internal-developers/testing/releases/1065.md b/docs/internal-developers/testing/releases/1065.md new file mode 100644 index 00000000000..6c30c278909 --- /dev/null +++ b/docs/internal-developers/testing/releases/1065.md @@ -0,0 +1,10 @@ +# Testing notes and ZIP for release 10.6.5 + +Zip file for testing: + +## WooCommerce Core + +### Revert "Performance: Cache script data in a transient for production builds" [#10509](https://github.com/woocommerce/woocommerce-blocks/pull/10509) + +1. Smoke test blocks. + diff --git a/docs/internal-developers/testing/releases/README.md b/docs/internal-developers/testing/releases/README.md index c47cc9f9d2f..1c31d9693bb 100644 --- a/docs/internal-developers/testing/releases/README.md +++ b/docs/internal-developers/testing/releases/README.md @@ -162,6 +162,7 @@ Every release includes specific testing instructions for new features and bug fi - [10.6.2](./1062.md) - [10.6.3](./1063.md) - [10.6.4](./1064.md) + - [10.6.5](./1065.md) diff --git a/readme.txt b/readme.txt index 29fb218b2fb..c811867eda4 100644 --- a/readme.txt +++ b/readme.txt @@ -81,6 +81,12 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 10.6.5 - 2021-08-09 = + +#### Bug Fixes + +- Avoid to cache script data in a transiet. ([10509](https://github.com/woocommerce/woocommerce-blocks/pull/10509)) + = 10.6.4 - 2021-08-04 = #### Bug Fixes From c3f1cabbf83ddb872e19231e363f5c5b03337b06 Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 9 Aug 2023 09:43:00 +0200 Subject: [PATCH 4/5] update zip link --- docs/internal-developers/testing/releases/1065.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internal-developers/testing/releases/1065.md b/docs/internal-developers/testing/releases/1065.md index 6c30c278909..06ebd7ccd65 100644 --- a/docs/internal-developers/testing/releases/1065.md +++ b/docs/internal-developers/testing/releases/1065.md @@ -1,6 +1,6 @@ # Testing notes and ZIP for release 10.6.5 -Zip file for testing: +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/12299587/woocommerce-gutenberg-products-block.zip) ## WooCommerce Core From 3e5ec3b597a0df04513c3de2808b283c9cbfb5de Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 9 Aug 2023 10:10:34 +0200 Subject: [PATCH 5/5] fix changelog --- readme.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.txt b/readme.txt index c811867eda4..a0498fa2c21 100644 --- a/readme.txt +++ b/readme.txt @@ -81,27 +81,27 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == -= 10.6.5 - 2021-08-09 = += 10.6.5 - 2023-08-09 = #### Bug Fixes -- Avoid to cache script data in a transiet. ([10509](https://github.com/woocommerce/woocommerce-blocks/pull/10509)) +- Avoid to cache script data in a transient. ([10509](https://github.com/woocommerce/woocommerce-blocks/pull/10509)) -= 10.6.4 - 2021-08-04 = += 10.6.4 - 2023-08-04 = #### Bug Fixes - Classic Template block registration: add defensive type handling. ([10475](https://github.com/woocommerce/woocommerce-blocks/pull/10475)) - Fixed an issue where modifications to the Cart/Checkout templates made in the site editor would not be visible on the front end. [#10462](https://github.com/woocommerce/woocommerce-blocks/pull/10462) -= 10.6.3 - 2021-08-02 = += 10.6.3 - 2023-08-02 = #### Bug Fixes - Fix styles for the Add to Cart Form block when used together with the Single Product block. ([10282](https://github.com/woocommerce/woocommerce-blocks/pull/10282)) - Blockified templates: Improve migration logic. [#10415](https://github.com/woocommerce/woocommerce-blocks/pull/10415) -= 10.6.2 - 2021-07-31 = += 10.6.2 - 2023-07-31 = #### Enhancements @@ -117,7 +117,7 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ - Single Product Template > Ensure extensions can't trigger fatal errors on customized single product templates without any post content blocks. ([10128](https://github.com/woocommerce/woocommerce-blocks/pull/10128)) - Cart and Checkout Page Migration: Inherit Page template and fix rendering. ([10375](https://github.com/woocommerce/woocommerce-blocks/pull/10375)) -= 10.6.1 - 2021-07-17 = += 10.6.1 - 2023-07-17 = #### Bug Fixes