From 7b6b5860337ea9e35abecee736356e35bc2949ec Mon Sep 17 00:00:00 2001 From: duffyduck Date: Sun, 17 May 2026 09:33:40 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20PortalPrivacy=20wei=C3=9Fe=20Seite=20?= =?UTF-8?q?=E2=80=93=20Hooks-Reihenfolge=20nach=20early-return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useState + useEffect für den Download-Token standen nach dem `if (isLoading) return ` early-return. Beim ersten Render gab es 2 Hooks, beim zweiten 4 → React-Hook-Order-Mismatch → Crash → weiße Seite. Mein Fehler aus der Download-Token-Migration (Runde 11). Hooks vor den early-return verschoben. Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/pages/portal/PortalPrivacy.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/portal/PortalPrivacy.tsx b/frontend/src/pages/portal/PortalPrivacy.tsx index 61b148b9..23c5148d 100644 --- a/frontend/src/pages/portal/PortalPrivacy.tsx +++ b/frontend/src/pages/portal/PortalPrivacy.tsx @@ -56,6 +56,15 @@ export default function PortalPrivacy() { }, }); + // Kurzlebigen Download-Token (60s) für den PDF-Link. Hooks MÜSSEN vor jedem + // early-return stehen (Rules of Hooks) – sonst weiße Seite beim ersten Render. + const [pdfToken, setPdfToken] = useState(null); + useEffect(() => { + let cancelled = false; + authApi.getDownloadToken().then((t) => { if (!cancelled) setPdfToken(t); }); + return () => { cancelled = true; }; + }, []); + const handleToggle = (consent: CustomerConsent) => { const newStatus: ConsentStatus = consent.status === 'GRANTED' ? 'WITHDRAWN' : 'GRANTED'; updateMutation.mutate({ consentType: consent.consentType, status: newStatus }); @@ -95,14 +104,6 @@ export default function PortalPrivacy() { const privacyPolicyHtml = data?.data?.privacyPolicyHtml || ''; const allGranted = consents.every((c) => c.status === 'GRANTED'); - // Kurzlebigen Download-Token (60s) für den PDF-Link. - const [pdfToken, setPdfToken] = useState(null); - useEffect(() => { - let cancelled = false; - authApi.getDownloadToken().then((t) => { if (!cancelled) setPdfToken(t); }); - return () => { cancelled = true; }; - }, []); - return (