From 10620a751726f1b44b66a8c868319196c58bae1b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:47:39 +0200 Subject: [PATCH] Release: 10.8.2 (https://github.com/woocommerce/woocommerce-blocks/pull/10517) * Revert woocommerce/woocommerce-blocks#10509 (https://github.com/woocommerce/woocommerce-blocks/pull/10513) * Revert "Revert "Performance: Cache script data in a transient for production builds" (https://github.com/woocommerce/woocommerce-blocks/pull/10509)" This reverts commit 5bcf8657ee44c9074917fb8c14a74523b5095dd2. * keep WP 6.2.2 as env to run E2E tests * Empty commit for release pull request * update changelog and testing instructions * bump version to 10.8.2 * update zip link --------- Co-authored-by: Luigi Teschio Co-authored-by: github-actions --- plugins/woocommerce-blocks/composer.json | 2 +- .../testing/releases/1082.md | 11 +++++ .../testing/releases/README.md | 1 + plugins/woocommerce-blocks/package-lock.json | 4 +- plugins/woocommerce-blocks/package.json | 2 +- plugins/woocommerce-blocks/readme.txt | 8 ++- plugins/woocommerce-blocks/src/Assets/Api.php | 49 +++++++++++++++++-- plugins/woocommerce-blocks/src/Package.php | 2 +- .../woocommerce-gutenberg-products-block.php | 2 +- 9 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 plugins/woocommerce-blocks/docs/internal-developers/testing/releases/1082.md diff --git a/plugins/woocommerce-blocks/composer.json b/plugins/woocommerce-blocks/composer.json index fcd15414076..6f01a7ff7a2 100644 --- a/plugins/woocommerce-blocks/composer.json +++ b/plugins/woocommerce-blocks/composer.json @@ -3,7 +3,7 @@ "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://woocommerce.com/", "type": "wordpress-plugin", - "version": "10.8.1", + "version": "10.8.2", "keywords": [ "gutenberg", "woocommerce", diff --git a/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/1082.md b/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/1082.md new file mode 100644 index 00000000000..d57ea204800 --- /dev/null +++ b/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/1082.md @@ -0,0 +1,11 @@ +# Testing notes and ZIP for release 10.8.2 + +Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/12301273/woocommerce-gutenberg-products-block.zip) + +## WooCommerce Core + +### Invalidate script data cache when site URL, scheme, or plugin name changes [#10278](https://github.com/woocommerce/woocommerce-blocks/pull/10278) + +1. Load up your site, ensuring WooCommerce Blocks is active. Visit a page with the Cart or Checkout block on it. +2. Disable and delete the WooCommerce Blocks plugin from your site. +3. Load up the page from Step 1 and ensure it loads correctly. diff --git a/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/README.md b/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/README.md index c868b259260..f3a73ecff32 100644 --- a/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/README.md +++ b/plugins/woocommerce-blocks/docs/internal-developers/testing/releases/README.md @@ -163,6 +163,7 @@ Every release includes specific testing instructions for new features and bug fi - [10.7.0](./1070.md) - [10.8.0](./1080.md) - [10.8.1](./1081.md) + - [10.8.2](./1082.md) diff --git a/plugins/woocommerce-blocks/package-lock.json b/plugins/woocommerce-blocks/package-lock.json index 713fac54633..a22bf86110b 100644 --- a/plugins/woocommerce-blocks/package-lock.json +++ b/plugins/woocommerce-blocks/package-lock.json @@ -1,12 +1,12 @@ { "name": "@woocommerce/block-library", - "version": "10.8.1", + "version": "10.8.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@woocommerce/block-library", - "version": "10.8.1", + "version": "10.8.2", "hasInstallScript": true, "license": "GPL-3.0+", "dependencies": { diff --git a/plugins/woocommerce-blocks/package.json b/plugins/woocommerce-blocks/package.json index 5124ba2028e..62a034897fb 100644 --- a/plugins/woocommerce-blocks/package.json +++ b/plugins/woocommerce-blocks/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/block-library", "title": "WooCommerce Blocks", "author": "Automattic", - "version": "10.8.1", + "version": "10.8.2", "description": "WooCommerce blocks for the Gutenberg editor.", "homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/", "keywords": [ diff --git a/plugins/woocommerce-blocks/readme.txt b/plugins/woocommerce-blocks/readme.txt index 4be4fda70bf..02679f35acf 100644 --- a/plugins/woocommerce-blocks/readme.txt +++ b/plugins/woocommerce-blocks/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.8.1 +Stable tag: 10.8.2 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -81,6 +81,12 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/ == Changelog == += 10.8.2 - 2023-08-09 = + +#### Bug Fixes + +- Ensure cached script data is refreshed following a site URL change, version change, or when switching between the WooCommerce Blocks feature plugin and WooCommerce Core. + = 10.8.1 - 2023-08-07 = #### Bug Fixes diff --git a/plugins/woocommerce-blocks/src/Assets/Api.php b/plugins/woocommerce-blocks/src/Assets/Api.php index 9550be10897..da8374c523a 100644 --- a/plugins/woocommerce-blocks/src/Assets/Api.php +++ b/plugins/woocommerce-blocks/src/Assets/Api.php @@ -32,6 +32,20 @@ class Api { */ private $script_data = null; + /** + * Stores the hash for the script data, made up of the site url, plugin version and package path. + * + * @var string + */ + private $script_data_hash; + + /** + * Stores the transient key used to cache the script data. This will change if the site is accessed via HTTPS or HTTP. + * + * @var string + */ + private $script_data_transient_key = 'woocommerce_blocks_asset_api_script_data'; + /** * Reference to the Package instance * @@ -47,6 +61,15 @@ class Api { public function __construct( Package $package ) { $this->package = $package; $this->disable_cache = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ! $this->package->feature()->is_production_environment(); + + // If the site is accessed via HTTPS, change the transient key. This is to prevent the script URLs being cached + // with the first scheme they are accessed on after cache expiry. + if ( is_ssl() ) { + $this->script_data_transient_key .= '_ssl'; + } + if ( ! $this->disable_cache ) { + $this->script_data_hash = $this->get_script_data_hash(); + } add_action( 'shutdown', array( $this, 'update_script_data_cache' ), 20 ); } @@ -92,6 +115,17 @@ class Api { return $path_to_metadata_from_plugin_root; } + /** + * Generates a hash containing the site url, plugin version and package path. + * + * Moving the plugin, changing the version, or changing the site url will result in a new hash and the cache will be invalidated. + * + * @return string The generated hash. + */ + private function get_script_data_hash() { + return md5( get_option( 'siteurl', '' ) . $this->package->get_version() . $this->package->get_path() ); + } + /** * Initialize and load cached script data from the transient cache. * @@ -102,9 +136,17 @@ class Api { return []; } - $transient_value = json_decode( (string) get_transient( 'woocommerce_blocks_asset_api_script_data' ), true ); + $transient_value = json_decode( (string) get_transient( $this->script_data_transient_key ), true ); - if ( empty( $transient_value ) || empty( $transient_value['script_data'] ) || empty( $transient_value['version'] ) || $transient_value['version'] !== $this->package->get_version() ) { + if ( + json_last_error() !== JSON_ERROR_NONE || + empty( $transient_value ) || + empty( $transient_value['script_data'] ) || + empty( $transient_value['version'] ) || + $transient_value['version'] !== $this->package->get_version() || + empty( $transient_value['hash'] ) || + $transient_value['hash'] !== $this->script_data_hash + ) { return []; } @@ -119,11 +161,12 @@ class Api { return; } set_transient( - 'woocommerce_blocks_asset_api_script_data', + $this->script_data_transient_key, wp_json_encode( array( 'script_data' => $this->script_data, 'version' => $this->package->get_version(), + 'hash' => $this->script_data_hash, ) ), DAY_IN_SECONDS * 30 diff --git a/plugins/woocommerce-blocks/src/Package.php b/plugins/woocommerce-blocks/src/Package.php index 5ee679131d3..b1cc793b1f4 100644 --- a/plugins/woocommerce-blocks/src/Package.php +++ b/plugins/woocommerce-blocks/src/Package.php @@ -109,7 +109,7 @@ class Package { NewPackage::class, function ( $container ) { // leave for automated version bumping. - $version = '10.8.1'; + $version = '10.8.2'; return new NewPackage( $version, dirname( __DIR__ ), diff --git a/plugins/woocommerce-blocks/woocommerce-gutenberg-products-block.php b/plugins/woocommerce-blocks/woocommerce-gutenberg-products-block.php index 373364b0a16..954d6853e5f 100644 --- a/plugins/woocommerce-blocks/woocommerce-gutenberg-products-block.php +++ b/plugins/woocommerce-blocks/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.8.1 + * Version: 10.8.2 * Author: Automattic * Author URI: https://woocommerce.com * Text Domain: woo-gutenberg-products-block