fix: StageTabView useCallback dependency loop — use ref for initial tab selection

This commit is contained in:
jlightner 2026-04-03 03:30:45 +00:00
parent c7a4d8aa27
commit 995d0c900d

View file

@ -537,6 +537,7 @@ function StageTabView({ videoId, runId, status }: { videoId: string; runId: stri
const [events, setEvents] = useState<PipelineEvent[]>([]);
const [loading, setLoading] = useState(true);
const [activeTab, setActiveTab] = useState<string | null>(null);
const initialSelect = useRef(false);
const load = useCallback(async (silent = false) => {
if (!silent) setLoading(true);
@ -548,14 +549,14 @@ function StageTabView({ videoId, runId, status }: { videoId: string; runId: stri
run_id: runId,
});
setEvents(res.items);
// Auto-select the most interesting tab: latest active or error stage
if (!silent && activeTab === null && res.items.length > 0) {
// Auto-select tab on first load only
if (!initialSelect.current && res.items.length > 0) {
initialSelect.current = true;
const stages = new Set(res.items.map((e) => e.stage));
const errorStage = res.items.find((e) => e.event_type === "error")?.stage;
if (errorStage) {
setActiveTab(errorStage);
} else {
// Pick the latest stage that has events
const lastStage = [...STAGE_TAB_ORDER].reverse().find((s) => stages.has(s.key));
if (lastStage) setActiveTab(lastStage.key);
}
@ -565,7 +566,7 @@ function StageTabView({ videoId, runId, status }: { videoId: string; runId: stri
} finally {
if (!silent) setLoading(false);
}
}, [videoId, runId, activeTab]);
}, [videoId, runId]);
useEffect(() => { void load(); }, [load]);