woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/frontend.tsx

140 lines
3.5 KiB
TypeScript
Raw Normal View History

Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
/**
* External dependencies
*/
import {
store,
navigate,
prefetch,
getElement,
getContext,
} from '@woocommerce/interactivity';
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
/**
* Internal dependencies
*/
import './style.scss';
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
export type ProductCollectionStoreContext = {
isPrefetchNextOrPreviousLink: boolean;
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
animation: 'start' | 'finish';
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
};
const isValidLink = ( ref: HTMLAnchorElement ) =>
ref &&
ref instanceof window.HTMLAnchorElement &&
ref.href &&
( ! ref.target || ref.target === '_self' ) &&
ref.origin === window.location.origin;
const isValidEvent = ( event: MouseEvent ) =>
event.button === 0 && // Left clicks only.
! event.metaKey && // Open in new tab (Mac).
! event.ctrlKey && // Open in new tab (Windows).
! event.altKey && // Download.
! event.shiftKey &&
! event.defaultPrevented;
/**
* Ensures the visibility of the first product in the collection.
* Scrolls the page to the first product if it's not in the viewport.
*
* @param {string} wcNavigationId Unique ID for each Product Collection block on page/post.
*/
function scrollToFirstProductIfNotVisible( wcNavigationId?: string ) {
if ( ! wcNavigationId ) {
return;
}
const productSelector = `[data-wc-navigation-id=${ wcNavigationId }] .wc-block-product-template .wc-block-product`;
const product = document.querySelector( productSelector );
if ( product ) {
const rect = product.getBoundingClientRect();
const isVisible =
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
( window.innerHeight ||
document.documentElement.clientHeight ) &&
rect.right <=
( window.innerWidth || document.documentElement.clientWidth );
// If the product is not visible, scroll to it.
if ( ! isVisible ) {
product.scrollIntoView( {
behavior: 'smooth',
block: 'start',
} );
}
}
}
const productCollectionStore = {
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
state: {
get startAnimation() {
return (
getContext< ProductCollectionStoreContext >().animation ===
'start'
);
},
get finishAnimation() {
return (
getContext< ProductCollectionStoreContext >().animation ===
'finish'
);
},
},
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
actions: {
*navigate( event: MouseEvent ) {
const ctx = getContext< ProductCollectionStoreContext >();
const { ref } = getElement();
const wcNavigationId = (
ref?.closest( '[data-wc-navigation-id]' ) as HTMLDivElement
)?.dataset?.wcNavigationId;
if ( isValidLink( ref ) && isValidEvent( event ) ) {
event.preventDefault();
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
// Don't start animation if it doesn't take long to navigate.
const timeout = setTimeout( () => {
ctx.animation = 'start';
}, 400 );
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
yield navigate( ref.href );
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
// Clear the timeout if the navigation is fast.
clearTimeout( timeout );
ctx.animation = 'finish';
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
ctx.isPrefetchNextOrPreviousLink = !! ref.href;
scrollToFirstProductIfNotVisible( wcNavigationId );
}
},
/**
* We prefetch the next or previous button page on hover.
* Optimizes user experience by preloading content for faster access.
*/
*prefetchOnHover() {
const { ref } = getElement();
if ( isValidLink( ref ) ) {
yield prefetch( ref.href );
}
},
},
callbacks: {
/**
* Prefetches content for next or previous links after initial user interaction.
* Reduces perceived load times for subsequent page navigations.
*/
*prefetch() {
const context = getContext< ProductCollectionStoreContext >();
const { ref } = getElement();
if ( context?.isPrefetchNextOrPreviousLink && isValidLink( ref ) ) {
yield prefetch( ref.href );
}
},
},
};
store( 'woocommerce/product-collection', productCollectionStore );