From 70b5c833d463ccee0b590b8363fbc21d01491aeb Mon Sep 17 00:00:00 2001 From: kitos Date: Fri, 29 May 2026 13:29:17 +0200 Subject: [PATCH] fix(tests): move showTemplateModal useState before early returns (React #310) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The useState hook was placed after the isLoading/error early returns, violating the Rules of Hooks. First render hit the early return without calling the hook; second render (after data loaded) called it, producing 'more hooks than previous render' — React error #310 and a white screen. Moved const [showTemplateModal] to the state block at the top of the component, alongside the other useState declarations. --- frontend/src/pages/TestDetailPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/pages/TestDetailPage.tsx b/frontend/src/pages/TestDetailPage.tsx index b5895ab..2d76590 100644 --- a/frontend/src/pages/TestDetailPage.tsx +++ b/frontend/src/pages/TestDetailPage.tsx @@ -65,6 +65,7 @@ export default function TestDetailPage() { }); const [toast, setToast] = useState<{ message: string; type: "success" | "error" } | null>(null); + const [showTemplateModal, setShowTemplateModal] = useState(false); // ── Queries ──────────────────────────────────────────────────── @@ -366,8 +367,6 @@ export default function TestDetailPage() { const canSaveAsTemplate = role === "red_lead" || role === "blue_lead" || role === "admin"; - const [showTemplateModal, setShowTemplateModal] = useState(false); - // ── Render ───────────────────────────────────────────────────── return (