From c8feb9a7e0f368e96cfc810523a048bdae77b91e Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 13 May 2021 00:28:06 -0700 Subject: [PATCH] Fix infinite loop when searching for Markings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Oops, we did an in-place sort on the search variables we passed to Apollo! This meant that Apollo's first read of the variables wouldn't match later reads, so it would always decide the variables had changed, causing an infinite re-render loop. Remember to copy existing arrays before sorting! 😅 Incidentally, this only happened for Markings, by coincidence: it's the only (I think) searchable zone label with multiple zone IDs, that don't sort alphabetically the same as they sort numerically. This `.sort()` sorts them alphabetically, whereas they come in numerical order in `allZones`, because that's the order the GQL server returns them in `build-cached-data.js`. --- src/app/WardrobePage/SearchPanel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/WardrobePage/SearchPanel.js b/src/app/WardrobePage/SearchPanel.js index b733d79..2b8f3f0 100644 --- a/src/app/WardrobePage/SearchPanel.js +++ b/src/app/WardrobePage/SearchPanel.js @@ -378,7 +378,7 @@ function useSearchResults(query, outfitState) { // Smooth over the data a bit, so that we can use key fields with confidence! const result = data?.itemSearch; const resultValue = result?.query; - const zoneStr = filterToZoneIds.sort().join(","); + const zoneStr = [...filterToZoneIds].sort().join(","); const resultZoneStr = (result?.zones || []) .map((z) => z.id) .sort()