Commit 448cee71749 for woocommerce
commit 448cee71749a6733218ef9f341c6f4688187b962
Author: Tung Du <dinhtungdu@gmail.com>
Date: Wed Nov 18 14:27:23 2026 +0700
Reduce product hydration size by omitting unused image data (#70086)
* Omit unused image data from product hydration state
Amp-Thread-ID: https://ampcode.com/threads/T-01a17ccc-0438-75dd-a1b6-a89367421f98
* Note in the products store README that images are not in client state
Amp-Thread-ID: https://ampcode.com/threads/T-01a1a42f-6f89-71df-b814-f9e5d3c07230
* Say in the products store README that images are left out for now
Amp-Thread-ID: https://ampcode.com/threads/T-01a1a42f-6f89-71df-b814-f9e5d3c07230
* Make the changelog entry say which data is left out
Amp-Thread-ID: https://ampcode.com/threads/T-01a1a42f-6f89-71df-b814-f9e5d3c07230
diff --git a/plugins/woocommerce/changelog/fix-65559-product-template-hydration b/plugins/woocommerce/changelog/fix-65559-product-template-hydration
new file mode 100644
index 00000000000..f53fbf1a98f
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-65559-product-template-hydration
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Reduce product page size by leaving image data out of the product state sent to interactive blocks.
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/README.md b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/README.md
index 2c4284592ba..d29b2d62164 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/README.md
+++ b/plugins/woocommerce/client/blocks/assets/js/base/stores/woocommerce/README.md
@@ -22,7 +22,7 @@ A locked, server-populated iAPI store that exposes WooCommerce products and vari
### When to use it
-Use this store when an interactive block needs to read product fields (price, SKU, stock, images, attributes, …) inside a directive, and the surrounding markup implies a single "current" product — a single product page, a product in a product-collection loop, a grouped-product child, a variation inside a variable product, etc.
+Use this store when an interactive block needs to read product fields (price, SKU, stock, attributes, …) inside a directive, and the surrounding markup implies a single "current" product — a single product page, a product in a product-collection loop, a grouped-product child, a variation inside a variable product, etc.
### Architecture at a glance
@@ -173,7 +173,7 @@ $interactive_attributes = $is_interactive
: '';
```
-Any `ProductResponseItem` field can be bound the same way, e.g. `state.productInContext.price_html`, `state.productInContext.stock_availability.text`, `state.mainProductInContext.name`.
+Any `ProductResponseItem` field except `images` can be bound the same way, e.g. `state.productInContext.price_html`, `state.productInContext.stock_availability.text`, `state.mainProductInContext.name`. The `images` field is temporarily left out of the store's state, on both the server and the client.
#### From JS (client)
diff --git a/plugins/woocommerce/src/Blocks/SharedStores/ProductsStore.php b/plugins/woocommerce/src/Blocks/SharedStores/ProductsStore.php
index 6ceea096a36..709bd69abb4 100644
--- a/plugins/woocommerce/src/Blocks/SharedStores/ProductsStore.php
+++ b/plugins/woocommerce/src/Blocks/SharedStores/ProductsStore.php
@@ -156,6 +156,19 @@ class ProductsStore {
);
}
+ /**
+ * Omit image metadata from client state; product galleries hydrate their own image data.
+ *
+ * @param array $products Products or variations keyed by ID.
+ * @return array Product data without images.
+ */
+ private static function remove_images( array $products ): array {
+ return array_map(
+ static fn( array $product ): array => array_diff_key( $product, array( 'images' => true ) ),
+ $products
+ );
+ }
+
/**
* Load a product into state.
*
@@ -178,7 +191,7 @@ class ProductsStore {
self::register_getters();
wp_interactivity_state(
self::$store_namespace,
- array( 'products' => array( $product_id => self::$products[ $product_id ] ) )
+ array( 'products' => self::remove_images( array( $product_id => self::$products[ $product_id ] ) ) )
);
return self::$products[ $product_id ];
@@ -235,7 +248,7 @@ class ProductsStore {
self::register_getters();
wp_interactivity_state(
self::$store_namespace,
- array( 'products' => $keyed_products )
+ array( 'products' => self::remove_images( $keyed_products ) )
);
return $keyed_products;
@@ -275,7 +288,7 @@ class ProductsStore {
self::register_getters();
wp_interactivity_state(
self::$store_namespace,
- array( 'productVariations' => $keyed_variations )
+ array( 'productVariations' => self::remove_images( $keyed_variations ) )
);
return $keyed_variations;