From 38f7d73e85c198836da13e4aa428f7ffcec94fae Mon Sep 17 00:00:00 2001 From: Corentin Date: Fri, 8 May 2026 12:21:17 +0200 Subject: [PATCH] =?UTF-8?q?fix(acadenice):=20hoist=20useDisclosure=20above?= =?UTF-8?q?=20early=20return=20=E2=80=94=20Patch=20022?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SpaceSidebar crashed with "Rendered more hooks than during the previous render" because R3.6 added a useDisclosure() AFTER `if (!space) return`. When `space` flipped from undefined (loading) to defined (loaded), the hook count changed and React threw, triggering the Error Boundary and blanking the page. This single bug was the root cause of 5 reported failures (R4.7 smoke): create page, sub-page, wikilink, /database, /template, /sync-block — all blocked by the white screen. Fix: hoist the hook above the conditional return. Hook order now stable. --- .../features/space/components/sidebar/space-sidebar.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/client/src/features/space/components/sidebar/space-sidebar.tsx b/apps/client/src/features/space/components/sidebar/space-sidebar.tsx index 4e75b9d1..ce52f5ca 100644 --- a/apps/client/src/features/space/components/sidebar/space-sidebar.tsx +++ b/apps/client/src/features/space/components/sidebar/space-sidebar.tsx @@ -73,14 +73,15 @@ export function SpaceSidebar() { const spaceRules = space?.membership?.permissions; const spaceAbility = useSpaceAbility(spaceRules); + // Acadenice R3.6 — template picker state (must be declared BEFORE any early + // return to keep React hook order stable across renders). + const [templatePickerOpened, { open: openTemplatePicker, close: closeTemplatePicker }] = + useDisclosure(false); + if (!space) { return <>; } - // Acadenice R3.6 — template picker state - const [templatePickerOpened, { open: openTemplatePicker, close: closeTemplatePicker }] = - useDisclosure(false); - function handleCreatePage() { tree?.create({ parentId: null, type: "internal", index: 0 }); }