fix: reset sidebar state on navigation to prevent ghost re-open
Use React's canonical "store info from previous renders" pattern: conditional setState during render resets sidebar when pathname changes, preventing the sidebar from re-opening on back-navigation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,9 +23,13 @@ export function DashboardShell({ children }: { children: ReactNode }) {
|
|||||||
const { isSignedIn } = useAuth();
|
const { isSignedIn } = useAuth();
|
||||||
const isOnboardingPath = pathname === "/onboarding";
|
const isOnboardingPath = pathname === "/onboarding";
|
||||||
const [sidebarState, setSidebarState] = useState({ open: false, path: pathname });
|
const [sidebarState, setSidebarState] = useState({ open: false, path: pathname });
|
||||||
// Sidebar auto-closes on navigation: when pathname changes, the derived
|
// Close sidebar on navigation using React's "store info from previous
|
||||||
// value becomes false without any setState or ref access during render.
|
// renders" pattern — conditional setState during render resets immediately
|
||||||
const sidebarOpen = sidebarState.path === pathname && sidebarState.open;
|
// without extra commits, avoiding both set-state-in-effect and refs rules.
|
||||||
|
if (sidebarState.path !== pathname) {
|
||||||
|
setSidebarState({ open: false, path: pathname });
|
||||||
|
}
|
||||||
|
const sidebarOpen = sidebarState.open;
|
||||||
|
|
||||||
const meQuery = useGetMeApiV1UsersMeGet<
|
const meQuery = useGetMeApiV1UsersMeGet<
|
||||||
getMeApiV1UsersMeGetResponse,
|
getMeApiV1UsersMeGetResponse,
|
||||||
|
|||||||
Reference in New Issue
Block a user