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

Release: 10.6.5 #10510

Merged
merged 5 commits into from
Aug 9, 2023
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
2 changes: 1 addition & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
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.6.4",
"version": "10.6.5",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
10 changes: 10 additions & 0 deletions docs/internal-developers/testing/releases/1065.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Testing notes and ZIP for release 10.6.5

Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/12299587/woocommerce-gutenberg-products-block.zip)

## 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.

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 @@ -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)



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.6.4",
"version": "10.6.5",
"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.6.4
Stable tag: 10.6.5
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.6.5 - 2021-08-09 =

Choose a reason for hiding this comment

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

Wrong year. This might get fixed automagically, but I'm mentioning it.


#### Bug Fixes

- Avoid to cache script data in a transiet. ([10509](https://github.com/woocommerce/woocommerce-blocks/pull/10509))

Choose a reason for hiding this comment

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

Typo in transient.


= 10.6.4 - 2021-08-04 =

#### Bug Fixes
Expand Down
104 changes: 22 additions & 82 deletions src/Assets/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -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,
);
}

/**
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.6.4';
$version = '10.6.5';
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.6.4
* Version: 10.6.5
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block
Expand Down
Loading