From 7a0eb7b24ae2af00a0469600a8f028ddc37ca83f Mon Sep 17 00:00:00 2001 From: 0xjjjjjj <0xjjjjjj@users.noreply.github.com> Date: Sat, 7 Mar 2026 20:18:08 -0800 Subject: [PATCH] fix: avoid setState in useEffect for sidebar close on navigation Use ref-based previous pathname check instead of useEffect + setState, which triggers the react-hooks/set-state-in-effect lint rule. Co-Authored-By: Claude Opus 4.6 --- frontend/src/components/templates/DashboardShell.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/templates/DashboardShell.tsx b/frontend/src/components/templates/DashboardShell.tsx index 4b37ac53..107dfdc6 100644 --- a/frontend/src/components/templates/DashboardShell.tsx +++ b/frontend/src/components/templates/DashboardShell.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import type { ReactNode } from "react"; import { usePathname, useRouter } from "next/navigation"; import { Menu, X } from "lucide-react"; @@ -39,9 +39,11 @@ export function DashboardShell({ children }: { children: ReactNode }) { const displayEmail = profile?.email ?? ""; // Close sidebar on navigation - useEffect(() => { - setSidebarOpen(false); - }, [pathname]); + const prevPathname = useRef(pathname); + if (prevPathname.current !== pathname) { + prevPathname.current = pathname; + if (sidebarOpen) setSidebarOpen(false); + } useEffect(() => { if (!isSignedIn || isOnboardingPath) return;