From 4dc6d321005954f070c895941250fcdb4fae3f1c Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Tue, 4 Aug 2026 20:03:56 +0530 Subject: [PATCH] fix(mobile): reset the unavailable decision synchronously on route change The decision state survived navigation on the same mounted screen: after the timer fired for one thread, the next route's first render still saw decided=true before the effect could reset it, flashing the unavailable screen the delay exists to prevent. The state is now keyed by route and reset during render, so a stale decision can never apply to a new route. Co-Authored-By: Claude Fable 5 --- .../features/threads/ThreadRouteScreen.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index fd94b57ec8..ab705f9155 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -158,14 +158,25 @@ function SubagentThreadRedirect({ const UNAVAILABLE_DECISION_DELAY_MS = 1_500; function useThreadUnavailableDecision(routeThreadKey: string | null, connectionReady: boolean) { - const [decided, setDecided] = useState(false); + const [decision, setDecision] = useState<{ + readonly key: string | null; + readonly decided: boolean; + }>({ key: routeThreadKey, decided: false }); + // A navigation reuses this mounted screen, and an effect-based reset leaves + // the previous route's fired decision visible for one render — exactly the + // flash the delay exists to prevent. Reset synchronously during render. + if (decision.key !== routeThreadKey) { + setDecision({ key: routeThreadKey, decided: false }); + } useEffect(() => { - setDecided(false); if (!connectionReady) return; - const timer = setTimeout(() => setDecided(true), UNAVAILABLE_DECISION_DELAY_MS); + const timer = setTimeout( + () => setDecision({ key: routeThreadKey, decided: true }), + UNAVAILABLE_DECISION_DELAY_MS, + ); return () => clearTimeout(timer); }, [routeThreadKey, connectionReady]); - return decided; + return decision.key === routeThreadKey && decision.decided; } export function ThreadRouteScreen(props: ThreadRouteScreenProps) {