From 73490a574142d08ec5552f6955921a265edf5149 Mon Sep 17 00:00:00 2001 From: Daniel Valenzuela Date: Fri, 6 Dec 2024 18:24:04 -0300 Subject: [PATCH] fix: avoid changing url when removing filters (#1530) * Makes the Active Tab Key independent from the URL, except for the initial load, where the active tab is set from the url. *Avoids unnecessarily changing SearchParams: Due to a limitation of the useSearchParams react hook, which uses a memoized value for the URL that becomes stale after selecting a tab, it unexpectedly changes the URL value. Unfortunately there's no way to completely avoid this, so if there's a usageKey url param, the hook setter function will be called and the URL will revert to the stale memoized url. --- src/library-authoring/LibraryAuthoringPage.tsx | 2 +- src/search-manager/SearchManager.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/library-authoring/LibraryAuthoringPage.tsx b/src/library-authoring/LibraryAuthoringPage.tsx index 202581e504..76cef54178 100644 --- a/src/library-authoring/LibraryAuthoringPage.tsx +++ b/src/library-authoring/LibraryAuthoringPage.tsx @@ -148,7 +148,7 @@ const LibraryAuthoringPage = ({ returnToLibrarySelection }: LibraryAuthoringPage } else if (currentPath && currentPath in ContentType) { setActiveKey(ContentType[currentPath]); } - }, [location.pathname]); + }, []); useEffect(() => { if (!componentPickerMode) { diff --git a/src/search-manager/SearchManager.ts b/src/search-manager/SearchManager.ts index 3776aaa30a..314c90020a 100644 --- a/src/search-manager/SearchManager.ts +++ b/src/search-manager/SearchManager.ts @@ -147,7 +147,9 @@ export const SearchContextProvider: React.FC<{ setBlockTypesFilter([]); setTagsFilter([]); setProblemTypesFilter([]); - setUsageKey(''); + if (usageKey !== '') { + setUsageKey(''); + } }, []); // Initialize a connection to Meilisearch: