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

Fix an endless loop when using product grid blocks inside product descriptions #6471

Merged
merged 4 commits into from
Jun 14, 2022

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented May 27, 2022

Works-around #6416 in the frontend.

Inspired by #6454.

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

User Facing Testing

  1. Enable Gutenberg for products adding this code (for example, at the end of functions.php of your theme):
function ps_activate_gutenberg( $can_edit, $post_type ) {
	if ( 'product' === $post_type ) {
		$can_edit = true;
	}
	return $can_edit;
}
add_filter( 'use_block_editor_for_post_type', 'ps_activate_gutenberg', 10, 2 );
  1. Create a page and add the On Sale Products block. Then, add a Hand-Picked Products block choosing the same three products that appeared on the On Sale Products block.
  2. Copy both blocks.
  3. Edit one of the On Sale products. Notice it will open the block editor.
  4. Paste the blocks you copied in step 2.
  5. Verify the editor doesn't crash.
  6. Preview the product in the frontend, and verify it renders properly.
  7. I recommend undoing the changes you did in step 4 or moving that product to trash because there are still some things not working properly when a product tries to query itself.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Fix an endless loop when using product grid blocks inside product descriptions

@Aljullu Aljullu added status: needs review type: bug The issue/PR concerns a confirmed bug. block-type: product-grid Issues related to/affecting all product-grid type blocks. labels May 27, 2022
@rubikuserbot rubikuserbot requested review from a team and albarin and removed request for a team May 27, 2022 05:59
@github-actions
Copy link
Contributor

github-actions bot commented May 27, 2022

Size Change: +3.17 kB (0%)

Total Size: 865 kB

Filename Size Change
build/active-filters.js 7.57 kB +142 B (+2%)
build/all-products-frontend.js 18.1 kB +2 B (0%)
build/all-products.js 33.5 kB +32 B (0%)
build/all-reviews.js 7.79 kB +7 B (0%)
build/attribute-filter-frontend.js 17.7 kB +3 B (0%)
build/attribute-filter.js 13.9 kB +173 B (+1%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB -1 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 5.06 kB -1 B (0%)
build/cart-blocks/cart-items-frontend.js 298 B -1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB -3 B (0%)
build/cart-blocks/cart-line-items-frontend.js 433 B +1 B (0%)
build/cart-blocks/empty-cart-frontend.js 347 B +1 B (0%)
build/cart-blocks/filled-cart-frontend.js 785 B +3 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.62 kB +2 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.13 kB +1 B (0%)
build/cart-blocks/order-summary-fee-frontend.js 272 B -1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 455 B +1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 427 B -1 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 432 B -1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.15 kB +1 B (0%)
build/cart-frontend.js 45.4 kB +112 B (0%)
build/cart.js 44.2 kB +108 B (0%)
build/checkout-blocks/billing-address-frontend.js 891 B -1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.84 kB +2 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.35 kB +3 B (0%)
build/checkout-blocks/fields-frontend.js 344 B -1 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.78 kB +1 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.25 kB -1 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.11 kB -1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 604 B +1 B (0%)
build/checkout-blocks/order-summary-taxes-frontend.js 431 B -1 B (0%)
build/checkout-blocks/payment-frontend.js 7.66 kB -2 B (0%)
build/checkout-blocks/shipping-address-frontend.js 996 B -1 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.72 kB +9 B (0%)
build/checkout-blocks/terms-frontend.js 1.22 kB -1 B (0%)
build/checkout-frontend.js 47.6 kB +134 B (0%)
build/checkout.js 45.5 kB +60 B (0%)
build/featured-category.js 13.2 kB +115 B (+1%)
build/featured-product.js 13.5 kB +86 B (+1%)
build/handpicked-products.js 7.39 kB -4 B (0%)
build/legacy-template.js 2.45 kB +249 B (+11%) ⚠️
build/mini-cart-component-frontend.js 16.6 kB +51 B (0%)
build/mini-cart-contents-block/filled-cart-frontend.js 229 B -1 B (0%)
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB +6 B (0%)
build/mini-cart-contents-block/footer-frontend.js 5.75 kB +117 B (+2%)
build/mini-cart-contents-block/products-table-frontend.js 290 B +1 B (0%)
build/mini-cart-contents-block/shopping-button-frontend.js 288 B +1 B (0%)
build/mini-cart-contents-block/title-frontend.js 367 B +1 B (0%)
build/mini-cart-contents.js 22.9 kB +101 B (0%)
build/mini-cart-frontend.js 1.72 kB -1 B (0%)
build/mini-cart.js 6.62 kB +522 B (+9%) 🔍
build/price-filter.js 8.9 kB +166 B (+2%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.66 kB +12 B (0%)
build/product-add-to-cart--product-button.js 565 B +1 B (0%)
build/product-add-to-cart-frontend.js 6.96 kB +4 B (0%)
build/product-add-to-cart.js 6.64 kB -6 B (0%)
build/product-best-sellers.js 7.48 kB +5 B (0%)
build/product-button-frontend.js 1.85 kB +7 B (0%)
build/product-button.js 1.09 kB +10 B (+1%)
build/product-categories.js 2.78 kB -3 B (0%)
build/product-category-list-frontend.js 922 B -1 B (0%)
build/product-category-list.js 502 B +1 B (0%)
build/product-category.js 8.59 kB +2 B (0%)
build/product-image-frontend.js 1.84 kB -2 B (0%)
build/product-image.js 1.07 kB +1 B (0%)
build/product-new.js 7.76 kB +4 B (0%)
build/product-on-sale.js 8.08 kB +6 B (0%)
build/product-price.js 1.5 kB +1 B (0%)
build/product-rating-frontend.js 1.15 kB -1 B (0%)
build/product-rating.js 731 B +1 B (0%)
build/product-sale-badge-frontend.js 1.09 kB -1 B (0%)
build/product-sale-badge.js 679 B +2 B (0%)
build/product-search.js 2.18 kB -1 B (0%)
build/product-stock-indicator-frontend.js 1.03 kB +1 B (0%)
build/product-stock-indicator.js 621 B +1 B (0%)
build/product-summary-frontend.js 1.33 kB -1 B (0%)
build/product-summary.js 918 B +1 B (0%)
build/product-tag-list-frontend.js 913 B -4 B (0%)
build/product-tag.js 8.12 kB +3 B (0%)
build/product-title-frontend.js 1.29 kB -4 B (0%)
build/product-title.js 908 B -2 B (0%)
build/product-top-rated.js 8 kB +1 B (0%)
build/products-by-attribute.js 8.69 kB +2 B (0%)
build/reviews-by-category.js 11.3 kB +9 B (0%)
build/reviews-by-product.js 12.4 kB +21 B (0%)
build/reviews-frontend.js 7.02 kB +1 B (0%)
build/single-product-frontend.js 21.5 kB +11 B (0%)
build/single-product.js 10.1 kB +11 B (0%)
build/stock-filter-frontend.js 7.32 kB +448 B (+7%) 🔍
build/stock-filter.js 7.24 kB +295 B (+4%)
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB +1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.75 kB +24 B (+1%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 20.5 kB +1 B (0%)
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB -1 B (0%)
build/vendors--product-add-to-cart-frontend.js 7.54 kB +1 B (0%)
build/wc-blocks-data.js 9.87 kB -3 B (0%)
build/wc-blocks-editor-style-rtl.css 5.08 kB +40 B (+1%)
build/wc-blocks-editor-style.css 5.08 kB +35 B (+1%)
build/wc-blocks-style-rtl.css 22.2 kB +9 B (0%)
build/wc-blocks-style.css 22.1 kB +9 B (0%)
build/wc-blocks-vendors.js 59 kB +24 B (0%)
build/wc-blocks.js 2.63 kB +4 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.59 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-order-summary-frontend.js 1.11 kB
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.34 kB
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.12 kB
build/checkout-blocks/order-note-frontend.js 1.07 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.66 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/totals-frontend.js 326 B
build/mini-cart-contents-block/empty-cart-frontend.js 364 B
build/mini-cart-contents-block/items-frontend.js 225 B
build/price-filter-frontend.js 12.5 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 499 B
build/product-price-frontend.js 1.94 kB
build/product-sku-frontend.js 380 B
build/product-sku.js 381 B
build/product-tag-list.js 495 B
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

@Aljullu
Copy link
Contributor Author

Aljullu commented May 30, 2022

Thanks for the review, @albarin! I'm holding off on merging this PR based on this comment, in case we need to make any additional changes here.

@tomasztunik
Copy link
Contributor

Had a quick look at this and thinking - if we remove the post id from the query, should we re-add the post from global post to the results so that it is included if it was requested?

I think the way it works with the change is it would exclude such post and it would be missing from results even if it was requested explicitly with post__in - or am I wrong?

@Aljullu
Copy link
Contributor Author

Aljullu commented Jun 2, 2022

I think the way it works with the change is it would exclude such post and it would be missing from results even if it was requested explicitly with post__in - or am I wrong?

You're right, @tomasztunik!

Had a quick look at this and thinking - if we remove the post id from the query, should we re-add the post from global post to the results so that it is included if it was requested?

That makes sense to me, did you investigate how that could be done? While I believe it's a great idea, I think we should keep in mind we are fixing a bug for an unsupported edge case, so I would be wary to spend too much time on this if the solution is not straight-forward.

@Aljullu Aljullu modified the milestones: 7.8.0, 7.9.0 Jun 6, 2022
@tomasztunik
Copy link
Contributor

Didn't really look into the implementation - I agree that this fix is still better than the app crashing. We might want to open up a follow-up issue to track the side-effect of this fix where we could continue the conversation if we should seek to cover this edge case.

@tomasztunik
Copy link
Contributor

The e2e failure with the wrong number of products returned for the filter by price is unrelated? seems odd failure for a flaky test?

@Aljullu
Copy link
Contributor Author

Aljullu commented Jun 6, 2022

Hmmm, that's weird. Tests are passing for me locally, and I see the same test is failing in another unrelated PR (#6505), so I would say it's unrelated. Also, I don't think filter blocks make use of BlocksWpQuery. 🤔

@Aljullu Aljullu self-assigned this Jun 8, 2022
@PanosSynetos
Copy link
Contributor

Hey @Aljullu - I was LMAFK last week - I'll make sure to reply to your comment today/tomorrow and possibly add one more commit to bring the "parent".

@PanosSynetos
Copy link
Contributor

@Aljullu all good - no need for a revision check 👉 #6454 (comment)

@PanosSynetos PanosSynetos merged commit a2682b4 into trunk Jun 14, 2022
@PanosSynetos PanosSynetos deleted the fix/6416-infinite-loop-product-grid-blocks branch June 14, 2022 08:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product-grid Issues related to/affecting all product-grid type blocks. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants