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 <[email protected]>
This commit is contained in:
Shivam SharmaandClaude Fable 5 authored and T3 Code Test committed 2026-08-14 15:04:12 +05:30
1 parent f6e005ba0f
commit 4dc6d32100
1 file changed
+15 -4
@@ -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) {