Fix hooks order violation in RunEncounters

Move hofTeam useMemo before early returns to comply with Rules of Hooks.
It was placed after the loading/error guards, causing a "rendered more
hooks than during the previous render" crash.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Julian Tabel
2026-02-09 10:22:54 +01:00
parent 08a5e5c621
commit 58d36c4433

View File

@@ -610,6 +610,13 @@ export function RunEncounters() {
} }
}, [organizedRoutes, encounterByRoute]) // eslint-disable-line react-hooks/exhaustive-deps }, [organizedRoutes, encounterByRoute]) // eslint-disable-line react-hooks/exhaustive-deps
// Resolve HoF team encounters from IDs
const hofTeam = useMemo(() => {
if (!run?.hofEncounterIds || run.hofEncounterIds.length === 0) return null
const idSet = new Set(run.hofEncounterIds)
return normalEncounters.filter((e) => idSet.has(e.id))
}, [run?.hofEncounterIds, normalEncounters])
if (isLoading || loadingRoutes) { if (isLoading || loadingRoutes) {
return ( return (
<div className="flex items-center justify-center py-16"> <div className="flex items-center justify-center py-16">
@@ -669,13 +676,6 @@ export function RunEncounters() {
(e) => e.status === 'caught' && e.faintLevel !== null, (e) => e.status === 'caught' && e.faintLevel !== null,
) )
// Resolve HoF team encounters from IDs
const hofTeam = useMemo(() => {
if (!run.hofEncounterIds || run.hofEncounterIds.length === 0) return null
const idSet = new Set(run.hofEncounterIds)
return normalEncounters.filter((e) => idSet.has(e.id))
}, [run.hofEncounterIds, normalEncounters])
const toggleGroup = (groupId: number) => { const toggleGroup = (groupId: number) => {
updateExpandedGroups((prev) => { updateExpandedGroups((prev) => {
const next = new Set(prev) const next = new Set(prev)