Skip to content

Commit

Permalink
Fix: Active Filters not working on for site templates (woocommerce#7346)
Browse files Browse the repository at this point in the history
* fix infinite rerendering issue for active filter block when use with PHP template or site editor

* group useQueryStateByKey calls

* update deps array
  • Loading branch information
dinhtungdu authored and senadir committed Nov 12, 2022
1 parent 490018a commit 9b89371
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions assets/js/blocks/active-filters/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const ActiveFiltersBlock = ( {
const [ minPrice, setMinPrice ] = useQueryStateByKey( 'min_price' );
const [ maxPrice, setMaxPrice ] = useQueryStateByKey( 'max_price' );

const [ productRatings, setProductRatings ] =
useQueryStateByKey( 'rating' );

const STOCK_STATUS_OPTIONS = getSetting( 'stockStatusOptions', [] );
const STORE_ATTRIBUTES = getSetting( 'attributes', [] );
const activeStockStatusFilters = useMemo( () => {
Expand Down Expand Up @@ -154,7 +157,9 @@ const ActiveFiltersBlock = ( {
( ! productAttributes.length &&
! urlContainsAttributeFilter( STORE_ATTRIBUTES ) )
) {
setIsLoading( false );
if ( isLoading ) {
setIsLoading( false );
}
return null;
}

Expand All @@ -164,7 +169,9 @@ const ActiveFiltersBlock = ( {
);

if ( ! attributeObject ) {
setIsLoading( false );
if ( isLoading ) {
setIsLoading( false );
}
return null;
}

Expand All @@ -183,12 +190,10 @@ const ActiveFiltersBlock = ( {
productAttributes,
componentHasMounted,
STORE_ATTRIBUTES,
isLoading,
blockAttributes.displayStyle,
] );

const [ productRatings, setProductRatings ] =
useQueryStateByKey( 'rating' );

/**
* Parse the filter URL to set the active rating fitlers.
* This code should be moved to Rating Filter block once it's implemented.
Expand Down

0 comments on commit 9b89371

Please sign in to comment.