fix: PortalPrivacy weiße Seite – Hooks-Reihenfolge nach early-return
useState + useEffect für den Download-Token standen nach dem `if (isLoading) return <Laden />` 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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<string | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
authApi.getDownloadToken().then((t) => { if (!cancelled) setPdfToken(t); });
|
||||||
|
return () => { cancelled = true; };
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleToggle = (consent: CustomerConsent) => {
|
const handleToggle = (consent: CustomerConsent) => {
|
||||||
const newStatus: ConsentStatus = consent.status === 'GRANTED' ? 'WITHDRAWN' : 'GRANTED';
|
const newStatus: ConsentStatus = consent.status === 'GRANTED' ? 'WITHDRAWN' : 'GRANTED';
|
||||||
updateMutation.mutate({ consentType: consent.consentType, status: newStatus });
|
updateMutation.mutate({ consentType: consent.consentType, status: newStatus });
|
||||||
@@ -95,14 +104,6 @@ export default function PortalPrivacy() {
|
|||||||
const privacyPolicyHtml = data?.data?.privacyPolicyHtml || '';
|
const privacyPolicyHtml = data?.data?.privacyPolicyHtml || '';
|
||||||
const allGranted = consents.every((c) => c.status === 'GRANTED');
|
const allGranted = consents.every((c) => c.status === 'GRANTED');
|
||||||
|
|
||||||
// Kurzlebigen Download-Token (60s) für den PDF-Link.
|
|
||||||
const [pdfToken, setPdfToken] = useState<string | null>(null);
|
|
||||||
useEffect(() => {
|
|
||||||
let cancelled = false;
|
|
||||||
authApi.getDownloadToken().then((t) => { if (!cancelled) setPdfToken(t); });
|
|
||||||
return () => { cancelled = true; };
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="flex items-center gap-3 mb-6">
|
<div className="flex items-center gap-3 mb-6">
|
||||||
|
|||||||
Reference in New Issue
Block a user