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
This commit is contained in:
Gigi
2025-10-05 03:38:42 +01:00
parent cc0b27f7cd
commit 91fe1711cd

View File

@@ -152,6 +152,17 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
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 (
<div className="reader empty">
@@ -171,17 +182,6 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
)
}
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 (
<div className="reader">
{title && (