From 78d8cf3739f1998e7cea060516c2aeabed4aed74 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 14 Oct 2022 19:41:52 -0700 Subject: [PATCH] Preload the prev/next item search pages I tried to do this earlier, but the caching problem from the previous commit (where we weren't including `id` for the search result in the GQL query) was causing it to do a like, infinite loop thing, where the preload results would cache-invalidate the current results, and so the 3 queries would just fight for which one's in the cache? But now that caching is working, this is working too! Makes it all feel a lot snappier :3 --- src/app/WardrobePage/SearchPanel.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/WardrobePage/SearchPanel.js b/src/app/WardrobePage/SearchPanel.js index b39d353..e59b0ca 100644 --- a/src/app/WardrobePage/SearchPanel.js +++ b/src/app/WardrobePage/SearchPanel.js @@ -92,6 +92,16 @@ function SearchResults({ currentPageNumber ); + // Preload the previous and next page of search results, with this quick + // ~hacky trick: just `useSearchResults` two more times, with some extra + // attention to skip the query when we don't know if it will exist! + useSearchResults(query, outfitState, currentPageNumber - 1, { + skip: currentPageNumber <= 1, + }); + useSearchResults(query, outfitState, currentPageNumber + 1, { + skip: numTotalPages == null || currentPageNumber >= numTotalPages, + }); + // This will save the `wornItemIds` when the SearchResults first mounts, and // keep it saved even after the outfit changes. We use this to try to restore // these items after the user makes changes, e.g., after they try on another