diff --git a/src/components/editor/CatalogTab.tsx b/src/components/editor/CatalogTab.tsx index f07c4b5..5512976 100644 --- a/src/components/editor/CatalogTab.tsx +++ b/src/components/editor/CatalogTab.tsx @@ -43,14 +43,12 @@ export default function CatalogTab({ } async function toggleSectionMacros(id: string) { - let next = true; - setSections((prev) => - prev.map((s) => { - if (s.id !== id) return s; - next = !s.showMacros; - return { ...s, showMacros: next }; - }), - ); + // Compute next from current state (NOT inside the setState updater — that runs + // during render, after this PATCH would already have read a stale value). + const section = sections.find((s) => s.id === id); + if (!section) return; + const next = !section.showMacros; + setSections((prev) => prev.map((s) => (s.id === id ? { ...s, showMacros: next } : s))); await api(slug, `/sections/${id}`, { method: 'PATCH', json: { showMacros: next } }); } const [dragSection, setDragSection] = useState(null);