From 854455c29da2ab19226b360d438e4199ddecd97b Mon Sep 17 00:00:00 2001 From: abhay-codes07 Date: Sat, 15 Aug 2026 15:01:25 +0530 Subject: [PATCH] fix(web): drop stale category filters when the space changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Category filter chips are stored in the URL (`?categories=`), so they survive a space switch. If the newly selected space has no documents in a selected category, the grid query keeps filtering by it and shows zero results — but the category chip only renders for facets that exist in the current space, so there is no visible control to clear and the user hits a dead end. Prune any selected categories the current space's facets don't contain, mirroring the existing agent-source reset a few lines above. --- apps/web/components/memories-grid.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index beaee36c..f3eb075b 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -395,6 +395,23 @@ export function MemoriesGrid({ } }, [agentSourceCounts, selectedAgentSource, setSelectedAgentSource]) + // Category filters are URL state that survives a space switch. Drop any that + // the current space's facets no longer contain, otherwise the grid stays + // filtered down to zero results with no visible pill to clear (the chip only + // renders for facets that exist here). Mirrors the agent-source reset above. + useEffect(() => { + if (!facetsData || selectedCategories.length === 0) return + const available = new Set( + facetsData.facets.map((facet) => facet.category), + ) + const stillValid = selectedCategories.filter((category) => + available.has(category), + ) + if (stillValid.length !== selectedCategories.length) { + void setSelectedCategories(stillValid.length > 0 ? stillValid : null) + } + }, [facetsData, selectedCategories, setSelectedCategories]) + const { data, error,