From 91fe1711cd66698631f2c80d849558f10ca40f49 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 5 Oct 2025 03:38:42 +0100 Subject: [PATCH] fix: move readingStats hook before early returns - Fixes React Hooks order violation - All hooks must be called unconditionally in the same order - Moved readingStats useMemo before the conditional returns - Resolves 'Rendered more hooks than during the previous render' error --- src/components/ContentPanel.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index 06b7c86d..79567bc8 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -152,6 +152,17 @@ const ContentPanel: React.FC = ({ return markdown }, [markdown, relevantHighlights]) + // Calculate reading time from content (must be before early returns) + const readingStats = useMemo(() => { + const content = markdown || html || '' + if (!content) return null + // Strip HTML tags for more accurate word count + const textContent = content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ') + return readingTime(textContent) + }, [html, markdown]) + + const hasHighlights = relevantHighlights.length > 0 + if (!selectedUrl) { return (
@@ -171,17 +182,6 @@ const ContentPanel: React.FC = ({ ) } - const hasHighlights = relevantHighlights.length > 0 - - // Calculate reading time from content - const readingStats = useMemo(() => { - const content = markdown || html || '' - if (!content) return null - // Strip HTML tags for more accurate word count - const textContent = content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ') - return readingTime(textContent) - }, [html, markdown]) - return (
{title && (