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

Interactivity API: Update interactive regions during client-side navigation #10200

Merged
merged 12 commits into from
Aug 3, 2023

Conversation

DAreRodz
Copy link
Collaborator

@DAreRodz DAreRodz commented Jul 14, 2023

With this PR, the Interactivity API exposes two directives to ease updating the Products Query block during client-side navigation.

  • data-wc-navigation-id: defines an ID for an interactive region (i.e., an element with the data-wc-interactive attribute). The ID matches the region between different pages and is used to render the SSRed content.
  • data-wc-navigation-link: formerly data-wc-link, just renamed to include the navigation namespace.

All the logic related to the client-side navigation meta tag has been removed, as it is not needed from now on.

In addition, I've added a couple of filters to the Products Query block in order to inject the directives mentioned above. You can see it working in this video:

Before After
Screen.Recording.2023-07-14.at.10.14.10.mov
Screen.Recording.2023-07-14.at.10.04.08.mov

Tracking issue: woocommerce/woocommerce#42486

Testing

Automated Tests

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

User Facing Testing

  1. Ensure that you are using the Blockified Product Catalog Template. If not, enable it.
  2. Open the Site Editor and go to the Product Catalog Template.
  3. In order to make pagination more noticeable, in the Product query block, disable the inherited query settings and manually modify the block markup to set the perPage prop inside the query attribute to 1.
  4. Visit the Product Catalog (/shop).
  5. Click on any link inside the Pagination block.
  6. Via dev tools, ensure that only the HTML inside the Query block is updated.
  7. Navigate back and forward.
  8. Via dev tools, ensure that only the HTML inside the Query block is updated.
  9. Click on any link outside the Pagination block
  10. Ensure that the browser navigates to the selected link.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Performance Impact

Changelog

Add suggested changelog entry here.

@DAreRodz
Copy link
Collaborator Author

Feel free to modify the PR description or add the convenient labels. Thanks! 🙏

cc: @gigitux, @Aljullu

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-10200.zip

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
reviews-frontend.js wc-settings, wp-a11y, wp-api-fetch, wp-compose, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill ⚠️
active-filters-frontend.js wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url ⚠️
all-products-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-blocks, wp-components, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️
attribute-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
cart-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️
checkout-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
filter-wrapper-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning ⚠️
mini-cart-frontend.js wc-price-format, wc-settings, wp-i18n, wp-polyfill ⚠️
price-filter-frontend.js react, wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-url ⚠️
rating-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
stock-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
mini-cart-component-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 470
  • Total errors: 2240

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

Comment on lines +120 to +123
if (
self::is_woocommerce_variation( $this->parsed_block ) &&
$instance->context['queryId'] === $this->parsed_block['attrs']['queryId']
) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used this check to ensure that we're adding the navigation-link directive only to the links inside the Pagination Block contained in the Products Query block. If you think there's a better way to do this, feel free to update the code. 😊

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, it'd be great if someone from Woo could review this part and give a thumbs up 🙂

Copy link
Contributor

@gigitux gigitux Jul 24, 2023

Choose a reason for hiding this comment

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

I would add another check:

core/query' === $block['blockName'] && self::is_woocommerce_variation( $this->parsed_block )....

The rest LGTM!

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2023

Size Change: +950 B (0%)

Total Size: 1.36 MB

Filename Size Change
build/active-filters-wrapper--mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-but--e791dc6c-style.js 957 B -2 B (0%)
build/active-filters.js 7.59 kB +1 B (0%)
build/all-products-rtl.css 4.24 kB +40 B (+1%)
build/all-products.css 4.24 kB +41 B (+1%)
build/all-products.js 41.8 kB -2 B (0%)
build/all-reviews.js 7.87 kB -2 B (0%)
build/attribute-filter-frontend.js 23 kB -13 B (0%)
build/attribute-filter-wrapper-frontend.js 7.69 kB -11 B (0%)
build/attribute-filter.js 13.3 kB -25 B (0%)
build/breadcrumbs.js 2.14 kB -3 B (0%)
build/cart-blocks/cart-items-style.js 229 B +1 B (0%)
build/cart-blocks/cart-order-summary-style.js 322 B +1 B (0%)
build/cart-blocks/order-summary-coupon-form-style.js 137 B +1 B (+1%)
build/cart-blocks/order-summary-discount-style.js 136 B -1 B (-1%)
build/cart-blocks/order-summary-taxes-style.js 177 B -1 B (-1%)
build/cart-blocks/proceed-to-checkout-style.js 1.09 kB -1 B (0%)
build/cart-rtl.css 9.59 kB -10 B (0%)
build/cart.css 9.58 kB -12 B (0%)
build/cart.js 45.2 kB +10 B (0%)
build/checkout-blocks/actions--checkout-blocks/terms-style.js 485 B -2 B (0%)
build/checkout-blocks/contact-information-style.js 608 B -1 B (0%)
build/checkout-blocks/fields-style.js 260 B -1 B (0%)
build/checkout-blocks/order-summary-cart-items-style.js 136 B -1 B (-1%)
build/checkout-blocks/order-summary-style.js 320 B -1 B (0%)
build/checkout-blocks/order-summary-taxes-style.js 177 B -1 B (-1%)
build/checkout-blocks/payment-style.js 461 B +2 B (0%)
build/checkout-blocks/pickup-options-style.js 443 B -1 B (0%)
build/checkout-blocks/shipping-address-style.js 475 B -3 B (-1%)
build/checkout-blocks/shipping-method-style.js 1.37 kB -1 B (0%)
build/checkout-blocks/shipping-methods-style.js 417 B -1 B (0%)
build/checkout-blocks/terms-style.js 677 B +2 B (0%)
build/checkout-rtl.css 9.22 kB -5 B (0%)
build/checkout.css 9.21 kB -6 B (0%)
build/checkout.js 47.8 kB +2 B (0%)
build/customer-account.js 3.19 kB -2 B (0%)
build/featured-category.js 15.1 kB +3 B (0%)
build/featured-product.js 15.3 kB -2 B (0%)
build/filter-wrapper.js 2.4 kB +1 B (0%)
build/handpicked-products.js 8.11 kB -4 B (0%)
build/legacy-template.js 8.93 kB -6 B (0%)
build/mini-cart-component-frontend.js 30.9 kB +38 B (0%)
build/mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-button--mini-cart-contents---358acf4e-style.js 293 B -1 B (0%)
build/mini-cart-contents-block/cart-button-style.js 388 B +1 B (0%)
build/mini-cart-contents-block/footer-style.js 2.4 kB +3 B (0%)
build/mini-cart-contents-block/products-table-style.js 5.45 kB +1 B (0%)
build/mini-cart-contents-block/shopping-button-style.js 403 B -1 B (0%)
build/mini-cart-contents-block/title-items-counter-style.js 302 B +1 B (0%)
build/mini-cart-contents-block/title-label-style.js 301 B +1 B (0%)
build/mini-cart-contents-block/title-style.js 445 B +2 B (0%)
build/mini-cart-contents.js 17.9 kB +1 B (0%)
build/mini-cart.js 6.37 kB +274 B (+4%)
build/price-filter.js 8.58 kB -2 B (0%)
build/product-add-to-cart.js 8.71 kB -2 B (0%)
build/product-best-sellers.js 8.45 kB -1 B (0%)
build/product-categories.js 2.71 kB -5 B (0%)
build/product-category.js 9.47 kB -1 B (0%)
build/product-collection.js 13.9 kB -2 B (0%)
build/product-gallery-large-image.js 2.01 kB +1 B (0%)
build/product-new.js 8.75 kB -1 B (0%)
build/product-price.js 1.67 kB -1 B (0%)
build/product-query.js 12.9 kB +190 B (+1%)
build/product-results-count.js 1.67 kB +1 B (0%)
build/product-search.js 2.63 kB +1 B (0%)
build/product-stock-indicator.js 729 B +1 B (0%)
build/product-summary.js 1.01 kB +1 B (0%)
build/product-tag.js 8.95 kB -2 B (0%)
build/product-top-rated.js 9.01 kB -2 B (0%)
build/rating-filter.js 6.94 kB -3 B (0%)
build/reviews-by-category.js 12.2 kB -3 B (0%)
build/reviews-by-product.js 13.4 kB -4 B (0%)
build/single-product.js 11.3 kB -8 B (0%)
build/stock-filter.js 7.64 kB -2 B (0%)
build/store-notices.js 1.69 kB -1 B (0%)
build/vendors--active-filters-wrapper--attribute-filter-wrapper--mini-cart-contents-block/cart-button--mi--d6bb29e6-style.js 606 B +1 B (0%)
build/vendors--cart-blocks/proceed-to-checkout-style.js 179 B +1 B (+1%)
build/vendors--checkout-blocks/shipping-method-style.js 11.7 kB -9 B (0%)
build/wc-blocks-editor-style-rtl.css 6.39 kB -9 B (0%)
build/wc-blocks-editor-style.css 6.4 kB -8 B (0%)
build/wc-blocks-rtl.css 2.54 kB +2 B (0%)
build/wc-blocks-vendors.js 65.5 kB -3 B (0%)
build/wc-blocks.css 2.54 kB +3 B (0%)
build/wc-interactivity.js 10.2 kB -245 B (-2%)
build/add-to-cart-form-rtl.css 380 B +380 B (new file) 🆕
build/add-to-cart-form.css 378 B +378 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 8.7 kB
build/active-filters-rtl.css 2.02 kB
build/active-filters-wrapper-frontend.js 7.64 kB
build/active-filters-wrapper-rtl.css 1.88 kB
build/active-filters-wrapper.css 1.88 kB
build/active-filters.css 2.02 kB
build/all-products-frontend.js 10.1 kB
build/all-reviews-rtl.css 1.84 kB
build/all-reviews.css 1.84 kB
build/attribute-filter-rtl.css 4.19 kB
build/attribute-filter-wrapper-rtl.css 4.06 kB
build/attribute-filter-wrapper.css 4.06 kB
build/attribute-filter.css 4.19 kB
build/blocks-checkout.js 35.1 kB
build/breadcrumbs-rtl.css 253 B
build/breadcrumbs.css 253 B
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB
build/cart-blocks/cart-accepted-payment-methods-style.js 137 B
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-cross-sells-products--product-price-frontend.js 2.91 kB
build/cart-blocks/cart-cross-sells-products-frontend.js 3.83 kB
build/cart-blocks/cart-cross-sells-products-style.js 137 B
build/cart-blocks/cart-cross-sells-style.js 253 B
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.17 kB
build/cart-blocks/cart-express-payment-frontend.js 719 B
build/cart-blocks/cart-express-payment-style.js 136 B
build/cart-blocks/cart-items-frontend.js 301 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.47 kB
build/cart-blocks/cart-line-items-frontend.js 1.06 kB
build/cart-blocks/cart-line-items-style.js 137 B
build/cart-blocks/cart-order-summary-frontend.js 1.28 kB
build/cart-blocks/cart-totals-frontend.js 307 B
build/cart-blocks/cart-totals-style.js 238 B
build/cart-blocks/empty-cart-frontend.js 347 B
build/cart-blocks/empty-cart-style.js 339 B
build/cart-blocks/filled-cart-frontend.js 655 B
build/cart-blocks/filled-cart-style.js 313 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.63 kB
build/cart-blocks/order-summary-discount-frontend.js 2.12 kB
build/cart-blocks/order-summary-fee-frontend.js 272 B
build/cart-blocks/order-summary-fee-style.js 137 B
build/cart-blocks/order-summary-heading-frontend.js 333 B
build/cart-blocks/order-summary-heading-style.js 335 B
build/cart-blocks/order-summary-shipping-frontend.js 17 kB
build/cart-blocks/order-summary-shipping-style.js 178 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-subtotal-style.js 136 B
build/cart-blocks/order-summary-taxes-frontend.js 434 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.43 kB
build/cart-frontend.js 29.9 kB
build/catalog-sorting-rtl.css 277 B
build/catalog-sorting.css 276 B
build/catalog-sorting.js 1.71 kB
build/checkout-blocks/actions-frontend.js 1.88 kB
build/checkout-blocks/actions-style.js 685 B
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.7 kB
build/checkout-blocks/billing-address-frontend.js 1.18 kB
build/checkout-blocks/billing-address-style.js 532 B
build/checkout-blocks/contact-information-frontend.js 2.04 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/fields-frontend.js 318 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.75 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.79 kB
build/checkout-blocks/order-summary-coupon-form-style.js 137 B
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB
build/checkout-blocks/order-summary-discount-style.js 137 B
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-fee-style.js 137 B
build/checkout-blocks/order-summary-frontend.js 1.28 kB
build/checkout-blocks/order-summary-shipping-frontend.js 17 kB
build/checkout-blocks/order-summary-shipping-style.js 137 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-subtotal-style.js 137 B
build/checkout-blocks/order-summary-taxes-frontend.js 435 B
build/checkout-blocks/payment-frontend.js 9.28 kB
build/checkout-blocks/pickup-options-frontend.js 4.84 kB
build/checkout-blocks/shipping-address-frontend.js 1.18 kB
build/checkout-blocks/shipping-method-frontend.js 2.62 kB
build/checkout-blocks/shipping-methods-frontend.js 6.41 kB
build/checkout-blocks/terms-frontend.js 1.55 kB
build/checkout-blocks/totals-frontend.js 347 B
build/checkout-blocks/totals-style.js 285 B
build/checkout-frontend.js 31.8 kB
build/customer-account-rtl.css 406 B
build/customer-account.css 406 B
build/featured-category-rtl.css 986 B
build/featured-category.css 987 B
build/featured-product-rtl.css 1.03 kB
build/featured-product.css 1.03 kB
build/filter-wrapper-frontend.js 14.3 kB
build/filter-wrapper-rtl.css 399 B
build/filter-wrapper.css 397 B
build/legacy-template-rtl.css 258 B
build/legacy-template.css 257 B
build/mini-cart-contents-block/cart-button-frontend.js 1.73 kB
build/mini-cart-contents-block/checkout-button-frontend.js 1.81 kB
build/mini-cart-contents-block/checkout-button-style.js 470 B
build/mini-cart-contents-block/empty-cart-frontend.js 360 B
build/mini-cart-contents-block/empty-cart-style.js 358 B
build/mini-cart-contents-block/filled-cart-frontend.js 267 B
build/mini-cart-contents-block/filled-cart-style.js 268 B
build/mini-cart-contents-block/footer-frontend.js 3.83 kB
build/mini-cart-contents-block/footer-rtl.css 419 B
build/mini-cart-contents-block/footer.css 418 B
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/items-style.js 237 B
build/mini-cart-contents-block/products-table--product-image--product-title-style.js 352 B
build/mini-cart-contents-block/products-table-frontend.js 582 B
build/mini-cart-contents-block/products-table-rtl.css 2.19 kB
build/mini-cart-contents-block/products-table.css 2.18 kB
build/mini-cart-contents-block/shopping-button-frontend.js 538 B
build/mini-cart-contents-block/title-frontend.js 1.9 kB
build/mini-cart-contents-block/title-items-counter-frontend.js 1.59 kB
build/mini-cart-contents-block/title-label-frontend.js 1.53 kB
build/mini-cart-contents-rtl.css 2.73 kB
build/mini-cart-contents.css 2.73 kB
build/mini-cart-frontend.js 2.85 kB
build/mini-cart-rtl.css 2.61 kB
build/mini-cart.css 2.61 kB
build/packages-style-rtl.css 3.59 kB
build/packages-style.css 3.59 kB
build/price-filter-frontend.js 14.6 kB
build/price-filter-rtl.css 2.71 kB
build/price-filter-wrapper-frontend.js 6.75 kB
build/price-filter-wrapper-rtl.css 2.56 kB
build/price-filter-wrapper.css 2.56 kB
build/price-filter.css 2.7 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-average-rating--product-button--product-image--product-price--product---1d132d69.js 272 B
build/product-add-to-cart--product-button--product-rating--product-rating-counter--product-rating-stars.js 151 B
build/product-add-to-cart--product-image--product-title.js 351 B
build/product-add-to-cart-frontend.js 8.67 kB
build/product-add-to-cart-rtl.css 1.39 kB
build/product-add-to-cart.css 1.4 kB
build/product-average-rating--product-button--product-image--product-price--product-rating--product-ratin--e23975b5.js 954 B
build/product-average-rating-frontend.js 1.72 kB
build/product-average-rating.js 397 B
build/product-button-frontend.js 4.96 kB
build/product-button-rtl.css 889 B
build/product-button.css 891 B
build/product-button.js 3.95 kB
build/product-categories-rtl.css 671 B
build/product-categories.css 670 B
build/product-details-rtl.css 413 B
build/product-details.css 410 B
build/product-gallery-large-image-rtl.css 314 B
build/product-gallery-large-image.css 313 B
build/product-gallery.js 2.3 kB
build/product-image-frontend.js 2.72 kB
build/product-image-gallery-rtl.css 322 B
build/product-image-gallery.css 322 B
build/product-image-rtl.css 951 B
build/product-image.css 949 B
build/product-image.js 1.57 kB
build/product-on-sale.js 8.76 kB
build/product-price-frontend.js 248 B
build/product-price-rtl.css 696 B
build/product-price.css 695 B
build/product-query-rtl.css 367 B
build/product-query.css 365 B
build/product-rating-counter-frontend.js 2.03 kB
build/product-rating-counter.js 687 B
build/product-rating-frontend.js 2.37 kB
build/product-rating-rtl.css 262 B
build/product-rating-stars-frontend.js 2.27 kB
build/product-rating-stars-rtl.css 914 B
build/product-rating-stars.css 916 B
build/product-rating-stars.js 937 B
build/product-rating.css 262 B
build/product-rating.js 1.04 kB
build/product-results-count-rtl.css 248 B
build/product-results-count.css 247 B
build/product-reviews-rtl.css 474 B
build/product-reviews.css 473 B
build/product-sale-badge-frontend.js 1.81 kB
build/product-sale-badge-rtl.css 392 B
build/product-sale-badge.css 389 B
build/product-sale-badge.js 665 B
build/product-search-rtl.css 435 B
build/product-search.css 434 B
build/product-sku-frontend.js 1.87 kB
build/product-sku-rtl.css 258 B
build/product-sku.css 258 B
build/product-sku.js 535 B
build/product-stock-indicator-frontend.js 2.06 kB
build/product-stock-indicator-rtl.css 250 B
build/product-stock-indicator.css 250 B
build/product-summary-frontend.js 2.28 kB
build/product-summary-rtl.css 571 B
build/product-summary.css 572 B
build/product-template-rtl.css 439 B
build/product-template.css 437 B
build/product-template.js 3.35 kB
build/product-title-frontend.js 2.23 kB
build/product-title-rtl.css 718 B
build/product-title.css 719 B
build/product-title.js 973 B
build/products-by-attribute.js 9.8 kB
build/rating-filter-frontend.js 21.4 kB
build/rating-filter-rtl.css 4.25 kB
build/rating-filter-wrapper-frontend.js 6.23 kB
build/rating-filter-wrapper-rtl.css 4.11 kB
build/rating-filter-wrapper.css 4.11 kB
build/rating-filter.css 4.24 kB
build/reviews-by-category-rtl.css 1.84 kB
build/reviews-by-category.css 1.84 kB
build/reviews-by-product-rtl.css 1.84 kB
build/reviews-by-product.css 1.84 kB
build/reviews-frontend.js 7.18 kB
build/single-product-rtl.css 399 B
build/single-product.css 397 B
build/stock-filter-frontend.js 21.6 kB
build/stock-filter-rtl.css 4.06 kB
build/stock-filter-wrapper-frontend.js 6.45 kB
build/stock-filter-wrapper-rtl.css 3.93 kB
build/stock-filter-wrapper.css 3.93 kB
build/stock-filter.css 4.06 kB
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-coupon-form--cart-blocks/order-summary--48e1e4bb-frontend.js 6.84 kB
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-shipping--checkout-blocks/billing-addr--d9f38f9d-frontend.js 4.2 kB
build/vendors--attribute-filter-wrapper-frontend.js 5.11 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.57 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 19.4 kB
build/vendors--checkout-blocks/pickup-options--checkout-blocks/shipping-methods-frontend.js 8.25 kB
build/vendors--checkout-blocks/shipping-method-frontend.js 12.4 kB
build/vendors--mini-cart-contents-block/products-table--price-filter-wrapper--product-price-style.js 5.27 kB
build/vendors--mini-cart-contents-block/products-table-style.js 3.16 kB
build/vendors--price-filter-wrapper-frontend.js 2.2 kB
build/vendors--product-add-to-cart-frontend.js 7.25 kB
build/vendors--rating-filter-wrapper-frontend.js 5.11 kB
build/vendors--stock-filter-wrapper-frontend.js 5.11 kB
build/wc-blocks-data.js 22.4 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 934 B
build/wc-blocks-registry.js 3.15 kB
build/wc-blocks-shared-context.js 1.1 kB
build/wc-blocks-shared-hocs.js 1.75 kB
build/wc-blocks.js 3.75 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.6 kB
build/wc-shipping-method-pickup-location.js 30.4 kB

compressed-size-action

Copy link
Collaborator

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

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

Great work! There are still a few things to review, but this looks mostly ready 🙂

assets/js/interactivity/router.js Show resolved Hide resolved
src/BlockTypes/ProductQuery.php Show resolved Hide resolved
src/BlockTypes/ProductQuery.php Outdated Show resolved Hide resolved
) {
$p = new \WP_HTML_Tag_Processor( $block_content );

while ( $p->next_tag( 'a' ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Taking into account that this is not an experiment anymore, maybe we could start with a prefetch strategy of only prefetching the previous/next links, and skipping the page number links?

cc: @gigitux, @Aljullu, any thoughts on the prefetching strategy for the pagination?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. I don't have a strong opinion, but prefetching the next and previous ones and skip the others makes sense to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll make that change.

Comment on lines +120 to +123
if (
self::is_woocommerce_variation( $this->parsed_block ) &&
$instance->context['queryId'] === $this->parsed_block['attrs']['queryId']
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, it'd be great if someone from Woo could review this part and give a thumbs up 🙂

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

I did a brief review and overall it looks good to me. Good work and exciting stuff! 👏 I will let the others do the proper review as they have more context on the Interactivity API.

One question I have is whether the plan is to merge this so it works with the Products (Beta) block or whether it would be better to wait until the Product Collection block is released. Has this been discussed? For context: the Product Collection block is a replacement for the Products (Beta) block that won't use the Gutenberg Query Loop block underneath.

Besides that, I left a couple of minor comments below. 👇

) {
$p = new \WP_HTML_Tag_Processor( $block_content );

while ( $p->next_tag( 'a' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good question. I don't have a strong opinion, but prefetching the next and previous ones and skip the others makes sense to me.

while ( $p->next_tag( 'a' ) ) {
$p->set_attribute(
'data-wc-navigation-link',
'{"prefetch":true,"scroll":false}'
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it depends on the use-case, but when using the Products block in the Product Catalog template, I think it should default to scrolling to top.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll make this change as well. 🙂

@DAreRodz DAreRodz requested review from Aljullu and luisherranz July 19, 2023 16:36
@DAreRodz
Copy link
Collaborator Author

I've addressed most of your suggestions. Ready for review again. 😊

Copy link
Collaborator

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

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

This looks great, David. Amazing work 👏

Let's wait for a review from Woo, tho. Especially this bit and an answer to these Albert's questions.

Comment on lines +148 to +152
if ( $is_previous ) {
$p->set_attribute( 'key', 'pagination-previous' );
} elseif ( $is_next ) {
$p->set_attribute( 'key', 'pagination-next' );
}
Copy link
Collaborator

@luisherranz luisherranz Jul 20, 2023

Choose a reason for hiding this comment

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

Cool. Time to add support for data-wc-key to avoid adding invalid HTML?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@DAreRodz I've added data-wc-key in #10604 so we should use it here as well.

Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

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

I just added a comment but it isn't a critical change. So LGTM! Nice work!

I want to echo the @Aljullu comment:

One question I have is whether the plan is to merge this so it works with the Products (Beta) block or whether it would be better to wait until the Product Collection block is released. Has this been discussed? For context: the Product Collection block is a replacement for the Products (Beta) block that won't use the Gutenberg Query Loop block underneath.

I don't think that it is a critical issue porting these changes on the Product Collection block, btw.

cc @imanish003 @kmanijak (they are working on the Product Collection)

* @param \WP_Block $instance The block instance.
*/
public function add_navigation_id_directive( $block_content, $block, $instance ) {
if ( self::is_woocommerce_variation( $block ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add another check:

core/query' === $block['blockName'] && self::is_woocommerce_variation( $this->parsed_block )

The rest LGTM!

@github-actions github-actions bot added this to the 10.8.0 milestone Jul 24, 2023
@kmanijak
Copy link
Contributor

One question I have is whether the plan is to merge this so it works with the Products (Beta) block or whether it would be better to wait until the Product Collection block is released. Has this been discussed? For context: the Product Collection block is a replacement for the Products (Beta) block that won't use the Gutenberg Query Loop block underneath.

I don't think that it is a critical issue porting these changes on the Product Collection block, btw.
cc @imanish003 @kmanijak (they are working on the Product Collection)

@gigitux, thanks for the ping!

First of all, I love the UX improvements this PR brings! And having said that, I think it is crucial to port these to Product Collection as soon as possible. When migrating from Products (Beta) to Product Collection, users would see a decreased performance, which could be perceived as a regression. I don't think it has to be covered within this PR, but would be great to cover it before or right after the initial release. We'd like to release Product Collection in one of the upcoming releases (1-2).

BTW, I may have a wrong impression, but checking the changes in this PR, it doesn't seem too hard to re-use that in Product Collection (I mean especially for someone experienced with Interactivity API).

@Aljullu
Copy link
Contributor

Aljullu commented Jul 26, 2023

I agree with what has been mentioned so far:

  1. If the entire product grid is visible on the page, I would avoid scrolling (I think scrollIntoView({block:'nearest'}) already handles that).
  2. If it's not, I would scroll to the top of the product grid, but I don't think we need to allow changing the selector.
  3. And also +1 from my side to using smooth.

@Aljullu
Copy link
Contributor

Aljullu commented Jul 26, 2023

Also, In woocommerce-gutenberg-products-block.php, we have:

Requires at least: 6.1

Huh, good catch! Actually this should be 6.2. We officially only support the latest WP version. 🤔

But this PR uses WP_HTML_Tag_Processor, which was introduced in 6.2.0 as mentioned here. I think we will need to do one of the following (unless I am missing something):

  1. Update Requires at least to 6.2 ,OR
  2. Conditionally support the features introduced in this PR , OR
  3. Figure out alternative to WP_HTML_Tag_Processor to update the $block_content

Once WP 6.3 is released in August, WC will update its supported versions to 6.2 or higher, so we should be good to go.


So, if I got the dates right, the tl;dr is:

  • for WC Blocks we need to do option 1 (Update Requires at least to 6.2)
  • for WC core we don't need to do anything

@tjcafferkey
Copy link
Contributor

I think @Aljullu has summed it up nicely, especially if the following statement is true:

If the entire product grid is visible on the page, I would avoid scrolling (I think scrollIntoView({block:'nearest'}) already handles that).

My assumption is that this behaviour will be most valuable to mobile users, but we like those have already said below me we shouldn't assume that the product grid is always going to extend beyond the height of the users screen.

but I don't think we need to allow changing the selector

I think we should also avoid doing this.

@luisherranz
Copy link
Collaborator

luisherranz commented Jul 26, 2023

If the entire product grid is visible on the page, I would avoid scrolling (I think scrollIntoView({block:'nearest'}) already handles that).

It does, but it also scrolls to the bottom when the list is bigger than the screen.

I've tried both nearest and start with a Products list that's both smaller and bigger than the viewport, but none of them are perfect:

  • nearest scrolls to the bottom when the list is bigger than the viewport. We want it to scroll to the top.
  • start scrolls to the top when the list is smaller than the viewport. We want it to not scroll at all.

https://codepen.io/luisherranz/pen/ExOdjRK

For now, my opinion would be to go with start. Even though I find the scroll to the top annoying when the top is already in the viewport, I think it's worse to have to manually scroll to the top of the list each time you paginate, especially when the list is very long.

I don't think we can modify the default behavior because as far as I know, the directive defined here is intended to be more generic and shouldn't be aware of block-specific details

Maybe we could try a new pattern for this: passing a callback.

<a
  href="..."
  data-wc-navigation-link='{ "prefetch": true, "scroll": "ref:actions.woocommerce.scrollToProducts" }'
></a>
store({
  actions: {
    woocommerce: {
      scrollToProducts: ({ ref }) => {
        ref.closest("[data-wc-navigation-id^='woo-products-'").scrollIntoView({
          behavior: "smooth",
          block: "start",
        });
      },
    },
  },
});

In the future, if what Albert mentioned here is the desired UX, we could introduce an Intersection Observer and use block: start only when the top of the Products list is not on the viewport.

EDIT: I documented this pattern here.

@Aljullu
Copy link
Contributor

Aljullu commented Jul 27, 2023

It does, but it also scrolls to the bottom when the list is bigger than the screen.

Oh, I wasn't aware of that. Thanks for pointing it out!

For now, my opinion would be to go with start. Even though I find the scroll to the top annoying when the top is already in the viewport, I think it's worse to have to manually scroll to the top of the list each time you paginate, especially when the list is very long.

It works for me. 👍 We can always iterate on this in the future if needed.

@imanish003
Copy link
Contributor

imanish003 commented Jul 27, 2023

Hey @luisherranz,

data-wc-navigation-link='{ "prefetch": true, "scroll": "ref:actions.woocommerce.scrollToProducts" }'

Thank you for sharing this and documenting this approach. This looks promising to me. I noticed that you have also commented on draft PR #10349. I have a few questions regarding this approach, which I will ask on the PR 🙂


As far as I understand, it seems that what @Aljullu mentioned here is the ideal behavior we would like to achieve. If so, should I continue working on draft PR #10349 and see if this could be achieved using the approach shared by @luisherranz in the above comment? CC: @tjcafferkey

@imanish003
Copy link
Contributor

I am going to bump the milestone of this PR as this doesn't have a blocker label.

@imanish003 imanish003 modified the milestones: 10.8.0, 10.9.0 Jul 31, 2023
@DAreRodz
Copy link
Collaborator Author

DAreRodz commented Aug 2, 2023

Hey, I'm just catching up with the conversation. I see a PR already opened (#10349) to explore the scroll behavior that was agreed upon (i.e., scroll smoothly to the top of the nearest Query block containing the link).

In any case, I guess we can merge this PR as it is, right? Or should we wait for the other PR to be ready? 🤔 There is also this discussion to figure out a better API for directives that could enable these use cases.

cc: @luisherranz @Aljullu @imanish003

@luisherranz
Copy link
Collaborator

I would disable the scroll for now (scroll: false in data-wp-navigation-link) which is a better UX than scrolling to the top, and I'd merge this. The other enhancement is not strictly necessary and can be done later.

@DAreRodz DAreRodz merged commit c250aea into trunk Aug 3, 2023
@DAreRodz DAreRodz deleted the add/data-wc-navigation-directives branch August 3, 2023 08:55
@imanish003
Copy link
Contributor

@luisherranz @DAreRodz Just to confirm, it looks like before merging this PR, we haven't disabled the scroll for now. That is intended, right?

I am confirming this because I will be implementing the same for the Product Collection block too.

@DAreRodz
Copy link
Collaborator Author

DAreRodz commented Aug 7, 2023

Oops! 🙈 Nope, it wasn't intended; nice catch @imanish003. I think I assumed it was disabled when I merged it... 😅

I can open a PR with a quick fix later today.

@imanish003
Copy link
Contributor

Sounds great! Thanks, @DAreRodz 🙌🏻

@DAreRodz
Copy link
Collaborator Author

DAreRodz commented Aug 9, 2023

I almost forgot; here it is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block-type: product-query Issues related to/affecting all product-query variations. skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants