Home > widget-integration > FilterController > handleScrollRestore

FilterController.handleScrollRestore() method

Handles scroll position restoration when returning to a product list. Restores scroll to previously viewed product when navigating back from product detail page.

This method: - Disables browser's automatic scroll restoration - Checks for stored product ID in session storage - Validates the product is in the current collection - Waits for product images to load (for auto-height layouts) - Scrolls to the previously viewed product - Cleans up stored values after restoration - Handles iOS page cache restoration (pageshow event)

Signature:

handleScrollRestore(): () => void;

Returns:

() => void

Cleanup function to remove pageshow event listener

Remarks

Uses session storage keys SELECTED_PRODUCT_ID and COLLECTION_SELECTED to maintain scroll position across navigation. For auto-height image layouts, waits up to 1 second (20 attempts × 50ms) for aspect ratio calculation.

Example

Override to customize scroll behavior:

window.boostWidgetIntegration.extend('FilterController', (FilterController) => {
  return class CustomFilterController extends FilterController {
    handleScrollRestore() {
      const cleanup = super.handleScrollRestore();

      // Add smooth scroll behavior
      const productId = this.filterHelper.getSessionStorage('SELECTED_PRODUCT_ID', 0);
      if (productId) {
        document.querySelector(`[data-product-id="${productId}"]`)
          ?.scrollIntoView({ behavior: 'smooth', block: 'center' });
      }

      return cleanup;
    }
  };
});