Commit ee1058fa8cd for woocommerce

commit ee1058fa8cd3f6ef62ace2533d6113fc70944237
Author: Copilot <198982749+Copilot@users.noreply.github.com>
Date:   Thu Aug 6 10:24:40 2026 +0200

    Fix: Reviews by Category block shows all reviews when published without a category selected (#67324)

    * Initial plan

    * fix: prevent Reviews by Category from showing all reviews when no category selected

    When a user publishes a Reviews by Category block without selecting any category,
    the block's save function writes `data-category-ids=""` (empty string) to the HTML.
    On the frontend, this empty string is falsy, so the category filter is skipped and
    all reviews are shown.

    Fix: In FrontendContainerBlock.render(), return null when categoryIds is an empty
    string. This prevents the unfiltered "all reviews" display when no category was
    selected for the block.

    Also adds a test to verify this behavior.

    Fixes #67180

    * Update empty review filter handling

    * Handle empty filtered review blocks

    * Add changefile(s) from automation for the following project(s): woocommerce

    * fix e2e test

    ---------

    Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
    Co-authored-by: Luigi Teschio <gigitux@gmail.com>
    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/67324-copilot-fix-reviews-by-category-issue b/plugins/woocommerce/changelog/67324-copilot-fix-reviews-by-category-issue
new file mode 100644
index 00000000000..6ebd465132b
--- /dev/null
+++ b/plugins/woocommerce/changelog/67324-copilot-fix-reviews-by-category-issue
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Prevent filtered review blocks from showing all reviews when no category or product is selected.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend-container-block.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend-container-block.tsx
index 167456e6c78..977e44f78f2 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend-container-block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend-container-block.tsx
@@ -93,10 +93,14 @@ class FrontendContainerBlock extends Component<

 	render() {
 		const { attributes } = this.props;
-		const { categoryIds, productId } = attributes;
+		const { categoryIds, productId, isFilteredReviewsBlock } = attributes;
 		const { reviewsToDisplay } = this.state;
 		const { order, orderby } = getSortArgs( this.state.orderby );

+		if ( isFilteredReviewsBlock && ! categoryIds && ! productId ) {
+			return null;
+		}
+
 		return (
 			// @ts-expect-error - TODO: Refactor WrappedComponent
 			<FrontendBlock
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend.ts b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend.ts
index a9d914a855b..6c2535c748b 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/reviews/frontend.ts
@@ -17,9 +17,13 @@ const selector = `
 const getProps = ( el: HTMLElement ) => {
 	const showOrderby = el.dataset.showOrderby === 'true';
 	const showLoadMore = el.dataset.showLoadMore === 'true';
+	const isFilteredReviewsBlock =
+		el.classList.contains( 'wp-block-woocommerce-reviews-by-product' ) ||
+		el.classList.contains( 'wp-block-woocommerce-reviews-by-category' );

 	return {
 		attributes: {
+			isFilteredReviewsBlock,
 			showOrderby,
 			showLoadMore,
 			showReviewDate: el.classList.contains( 'has-date' ),
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-category/reviews-by-category.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-category/reviews-by-category.block_theme.spec.ts
index fa8a07c2611..8f389a700d9 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-category/reviews-by-category.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-category/reviews-by-category.block_theme.spec.ts
@@ -6,15 +6,15 @@ import { expect, test } from '@woocommerce/e2e-utils';
 /**
  * Internal dependencies
  */
-import { allReviews, hoodieReviews } from '../../../test-data/blocks/data/data';
+import { hoodieReviews } from '../../../test-data/blocks/data/data';

-const latestReview = allReviews[ allReviews.length - 1 ];
+const latestReview = hoodieReviews[ hoodieReviews.length - 1 ];

-const highestRating = [ ...allReviews ].sort(
+const highestRating = [ ...hoodieReviews ].sort(
 	( a, b ) => b.rating - a.rating
 )[ 0 ];

-const lowestRating = [ ...allReviews ].sort(
+const lowestRating = [ ...hoodieReviews ].sort(
 	( a, b ) => a.rating - b.rating
 )[ 0 ];

@@ -24,12 +24,7 @@ test.describe( `${ BLOCK_NAME } Block`, () => {
 	test.beforeEach( async ( { admin, editor } ) => {
 		await admin.createNewPost();
 		await editor.insertBlock( { name: BLOCK_NAME } );
-	} );

-	test( 'block can be inserted and it successfully renders a review in the editor and the frontend', async ( {
-		page,
-		editor,
-	} ) => {
 		const blockLocator = await editor.getBlockByName( BLOCK_NAME );
 		const categoryCheckbox = blockLocator.getByRole( 'checkbox', {
 			name: 'Clothing',
@@ -37,11 +32,14 @@ test.describe( `${ BLOCK_NAME } Block`, () => {
 		} );
 		await categoryCheckbox.check();
 		await expect( categoryCheckbox ).toBeChecked();
-		const doneButton = blockLocator.getByRole( 'button', {
-			name: 'Done',
-		} );
-		await doneButton.click();

+		await blockLocator.getByRole( 'button', { name: 'Done' } ).click();
+	} );
+
+	test( 'block can be inserted and it successfully renders a review in the editor and the frontend', async ( {
+		page,
+		editor,
+	} ) => {
 		await expect(
 			editor.canvas.getByText( hoodieReviews[ 0 ].review )
 		).toBeVisible();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-product/reviews-by-product.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-product/reviews-by-product.block_theme.spec.ts
index edbca924d12..fe9a6b7d82d 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-product/reviews-by-product.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/reviews-by-product/reviews-by-product.block_theme.spec.ts
@@ -6,17 +6,17 @@ import { expect, test } from '@woocommerce/e2e-utils';
 /**
  * Internal dependencies
  */
-import { allReviews, hoodieReviews } from '../../../test-data/blocks/data/data';
+import { hoodieReviews } from '../../../test-data/blocks/data/data';

 const BLOCK_NAME = 'woocommerce/reviews-by-product';

-const latestReview = allReviews[ allReviews.length - 1 ];
+const latestReview = hoodieReviews[ hoodieReviews.length - 1 ];

-const highestRating = [ ...allReviews ].sort(
+const highestRating = [ ...hoodieReviews ].sort(
 	( a, b ) => b.rating - a.rating
 )[ 0 ];

-const lowestRating = [ ...allReviews ].sort(
+const lowestRating = [ ...hoodieReviews ].sort(
 	( a, b ) => a.rating - b.rating
 )[ 0 ];

@@ -24,23 +24,20 @@ test.describe( `${ BLOCK_NAME } Block`, () => {
 	test.beforeEach( async ( { admin, editor } ) => {
 		await admin.createNewPost();
 		await editor.insertBlock( { name: BLOCK_NAME } );
-	} );

-	test( 'block can be inserted and it successfully renders a review in the editor and the frontend', async ( {
-		page,
-		editor,
-	} ) => {
 		const productCheckbox = editor.canvas.getByLabel(
 			'Hoodie, has 2 reviews'
 		);
 		await productCheckbox.check();
 		await expect( productCheckbox ).toBeChecked();

-		const doneButton = editor.canvas.getByRole( 'button', {
-			name: 'Done',
-		} );
-		await doneButton.click();
+		await editor.canvas.getByRole( 'button', { name: 'Done' } ).click();
+	} );

+	test( 'block can be inserted and it successfully renders a review in the editor and the frontend', async ( {
+		page,
+		editor,
+	} ) => {
 		await expect(
 			editor.canvas.getByText( hoodieReviews[ 0 ].review )
 		).toBeVisible();