Skip to content

Commit c6ec479

Browse files
chemsseddineclaude
andauthored
🐛 fix: Move useEffect before conditional return in AppLayout (#41)
The `useEffect` hook was called after a conditional early return, violating React's Rules of Hooks. Moved `toggleSidebar` and its `useEffect` above the `AccessDenied` guard so hooks are always called in the same order. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f89df58 commit c6ec479

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/routes/_app.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ function AppLayout() {
5050
});
5151
const pathname = router.state.location.pathname;
5252

53-
if (!isLoading && !isError && !hasCapability(SystemCapabilities.ACCESS_ADMIN)) {
54-
return <AccessDenied />;
55-
}
56-
57-
const matchedKey = Object.keys(ROUTE_TITLE_KEYS).find((route) =>
58-
route === '/' ? pathname === '/' : pathname.startsWith(route),
59-
);
60-
const title = matchedKey ? localize(ROUTE_TITLE_KEYS[matchedKey]) : undefined;
61-
6253
const toggleSidebar = () =>
6354
setSidebarCollapsed((prev) => {
6455
const next = !prev;
@@ -77,6 +68,15 @@ function AppLayout() {
7768
return () => document.removeEventListener('keydown', handleKeyDown);
7869
}, []);
7970

71+
if (!isLoading && !isError && !hasCapability(SystemCapabilities.ACCESS_ADMIN)) {
72+
return <AccessDenied />;
73+
}
74+
75+
const matchedKey = Object.keys(ROUTE_TITLE_KEYS).find((route) =>
76+
route === '/' ? pathname === '/' : pathname.startsWith(route),
77+
);
78+
const title = matchedKey ? localize(ROUTE_TITLE_KEYS[matchedKey]) : undefined;
79+
8080
return (
8181
<div className="flex h-screen overflow-hidden">
8282
<Sidebar user={user} collapsed={sidebarCollapsed} onToggle={toggleSidebar} />

0 commit comments

Comments
 (0)