fix human language tab empty state on first navigation

Retry hierarchy loading once when initial tab navigation returns empty, so content appears immediately without manual page refresh.

Made-with: Cursor
This commit is contained in:
Yared Yemane 2026-04-14 09:03:01 -07:00
parent a006aa5c85
commit a8e4ef76e9

View File

@ -437,27 +437,43 @@ export function HumanLanguagePage() {
) )
setCollapsedModuleIds(moduleIds) setCollapsedModuleIds(moduleIds)
setCollapsedSubModuleIds(subModuleIds) setCollapsedSubModuleIds(subModuleIds)
return nextSubCategories.length
} finally { } finally {
if (showLoading) setLoading(false) if (showLoading) setLoading(false)
} }
} }
useEffect(() => { useEffect(() => {
let cancelled = false
const run = async () => { const run = async () => {
setLoading(true) setLoading(true)
try { try {
await loadHierarchy() const count = await loadHierarchy(false)
// On first navigation after login, the first hierarchy request can race auth refresh.
// Retry once if it comes back empty so users don't need a manual browser refresh.
if (!cancelled && count === 0) {
await new Promise((resolve) => setTimeout(resolve, 650))
if (!cancelled) {
await loadHierarchy(false)
}
}
const saved = sessionStorage.getItem(HUMAN_LANGUAGE_SCROLL_KEY) const saved = sessionStorage.getItem(HUMAN_LANGUAGE_SCROLL_KEY)
const targetY = saved ? Number(saved) : 0 const targetY = saved ? Number(saved) : 0
if (Number.isFinite(targetY) && targetY > 0) { if (Number.isFinite(targetY) && targetY > 0) {
window.requestAnimationFrame(() => window.scrollTo({ top: targetY, behavior: "auto" })) window.requestAnimationFrame(() => window.scrollTo({ top: targetY, behavior: "auto" }))
setTimeout(() => window.scrollTo({ top: targetY, behavior: "auto" }), 250) setTimeout(() => window.scrollTo({ top: targetY, behavior: "auto" }), 250)
} }
} catch (error) {
console.error("Failed to load human-language hierarchy:", error)
toast.error("Failed to load Human Language data")
} finally { } finally {
setLoading(false) if (!cancelled) setLoading(false)
} }
} }
run().catch(() => undefined) run().catch(() => undefined)
return () => {
cancelled = true
}
}, []) }, [])
useEffect(() => { useEffect(() => {