fix(acadenice): hoist useDisclosure above early return — Patch 022

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.
This commit is contained in:
Corentin JOGUET 2026-05-08 12:21:17 +02:00
parent 60d64822e4
commit 38f7d73e85

View file

@ -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 });
}