From f7486162c6c8ef5836d82dc14c7daae484c68fc3 Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Wed, 11 Nov 2026 12:30:10 +0530 Subject: [PATCH] fix(tools): ensure switching workspace or category resets scroll to top --- src/components/sections/ToolGridSection.tsx | 23 ++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/sections/ToolGridSection.tsx b/src/components/sections/ToolGridSection.tsx index 0c1cf8b..f0e5a75 100644 --- a/src/components/sections/ToolGridSection.tsx +++ b/src/components/sections/ToolGridSection.tsx @@ -486,13 +486,34 @@ export function ToolGridSection({ return () => window.removeEventListener('hashchange', syncFromHash); }, [categorizedTools]); - // Handle Category Selection with URL Hash reflection + const isMountedRef = useRef(false); + + // Smoothly scroll window to top whenever active category or workspace changes + useEffect(() => { + if (!isMountedRef.current) { + isMountedRef.current = true; + return; + } + if (typeof window !== 'undefined') { + window.scrollTo({ top: 0, behavior: 'smooth' }); + const rafId = requestAnimationFrame(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); + return () => cancelAnimationFrame(rafId); + } + }, [selectedCategory]); + + // Handle Category Selection with URL Hash reflection and guaranteed scroll to top const handleSelectCategory = (catId: string) => { setSelectedCategory(catId); if (searchQuery) setSearchQuery(''); if (typeof window !== 'undefined') { const newHash = catId === 'all' ? '' : `#category-${catId}`; window.history.replaceState(null, '', newHash || window.location.pathname); + window.scrollTo({ top: 0, behavior: 'smooth' }); + requestAnimationFrame(() => { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); } };