diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a8a21e828b5..6a39a7a247af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## Next release -/ +### Fixed + +- Fixed bug in Ideas Map view that caused an infinite loop of requests when Idea sort order was changed ## 2022-03-29 diff --git a/front/app/hooks/useIdeaMarkers.ts b/front/app/hooks/useIdeaMarkers.ts index 3eec558a02fb..8847925da829 100644 --- a/front/app/hooks/useIdeaMarkers.ts +++ b/front/app/hooks/useIdeaMarkers.ts @@ -23,6 +23,10 @@ export default function useIdeaMarkers({ IIdeaMarkerData[] | undefined | null >(undefined); + // Stringifying the project IDs and topics to make useEffect dependency array happy + const stringifiedProjectIds = JSON.stringify(projectIds); + const stringifiedTopics = JSON.stringify(topics); + useEffect(() => { setIdeaMarkers(undefined); @@ -30,18 +34,18 @@ export default function useIdeaMarkers({ queryParameters: { 'page[size]': 2000, location_required: true, - projects: projectIds, + projects: JSON.parse(stringifiedProjectIds), phase: phaseId, sort: sort || ideaDefaultSortMethodFallback, search: search || undefined, - topics: topics || undefined, + topics: JSON.parse(stringifiedTopics) || undefined, }, }).observable.subscribe((response) => { setIdeaMarkers(!isNilOrError(response) ? response.data : null); }); return () => subscription.unsubscribe(); - }, [phaseId, projectIds, sort, search, topics]); + }, [phaseId, stringifiedProjectIds, sort, search, stringifiedTopics]); return ideaMarkers; }