gatsbyjs / gatsby-starter-shopify

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart
https://shopify-demo.gatsbyjs.com/
BSD Zero Clause License
311 stars 137 forks source link

Repair filtering by clearing pagination pointers #39

Open MaSchVam opened 3 years ago

MaSchVam commented 3 years ago

The pagination-pointer state cursors that is currently being set with setCursors, seems to be the culprit when it comes to how the filtering breaks sometimes.

This can easily be tested by navigating back and forth on any product archive that has pagination available - followed by entering a search.

A search, or a filtering of the products at this point, will return a data object with 0 products. Odd behaviour also occur, if a filtering is attempted, while not on the first page of any search/filtering result.

By unsetting the navigation pointer state in this side-effect, and by adding the sortKey state to the dependency array, we can fully reset the search archive every time a filter is changed, or a new search is entered.