Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Release: 10.8.2 #10517

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions docs/internal-developers/testing/releases/1082.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions docs/internal-developers/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


<!-- FEEDBACK -->
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 7 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
49 changes: 46 additions & 3 deletions src/Assets/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 );
}

Expand Down Expand Up @@ -92,6 +115,17 @@ public function get_block_metadata_path( $block_name, $path = '' ) {
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.
*
Expand All @@ -102,9 +136,17 @@ private function get_cached_script_data() {
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 [];
}

Expand All @@ -119,11 +161,12 @@ public function update_script_data_cache() {
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
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '10.8.1';
$version = '10.8.2';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-gutenberg-products-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down