Fix infinite loop when searching for Markings

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`.
This commit is contained in:
Emi Matchu 2021-05-13 00:28:06 -07:00
parent b521f79a13
commit c8feb9a7e0

View file

@ -378,7 +378,7 @@ function useSearchResults(query, outfitState) {
// Smooth over the data a bit, so that we can use key fields with confidence! // Smooth over the data a bit, so that we can use key fields with confidence!
const result = data?.itemSearch; const result = data?.itemSearch;
const resultValue = result?.query; const resultValue = result?.query;
const zoneStr = filterToZoneIds.sort().join(","); const zoneStr = [...filterToZoneIds].sort().join(",");
const resultZoneStr = (result?.zones || []) const resultZoneStr = (result?.zones || [])
.map((z) => z.id) .map((z) => z.id)
.sort() .sort()