Skip to content

Commit 45ebb05

Browse files
t3dotggclaude
andcommitted
fix(mobile): the thread list shows server changes after a tab round trip
On iPhone each tab slot shows its own copy of the Home route, and all of them report to one visibility store. A tab switch ends on the leaving slot's disappear, so after Chats > Settings > Chats (or PRs, or Usage) the store said Home was hidden and the list stopped reading thread data until the next focus event. A disappear now hides Home only when another route has the focus, and a list in a tab slot that is not the selected one stays paused. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 2482b03 commit 45ebb05

3 files changed

Lines changed: 75 additions & 9 deletions

File tree

‎apps/mobile/src/Stack.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,11 @@ const RootStackConfig = createWorkspaceStackNavigator({
493493
Home: createNativeStackScreen({
494494
screen: WorkspaceRootScreen,
495495
linking: "",
496-
listeners: {
496+
listeners: ({ navigation }) => ({
497497
transitionStart: ({ data }) => recordHomeTransitionStart(data.closing),
498-
transitionEnd: ({ data }) => recordHomeTransitionEnd(data.closing),
498+
transitionEnd: ({ data }) => recordHomeTransitionEnd(data.closing, navigation.isFocused()),
499499
focus: recordHomeFocus,
500-
},
500+
}),
501501
options: {
502502
...pageRoute({ duoMinimize: "never", root: true }),
503503
contentStyle: { backgroundColor: "transparent" },

‎apps/mobile/src/features/home/home-route-visibility.test.tsx‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { act, useLayoutEffect } from "react";
44
import { createRoot } from "react-dom/client";
55
import { expect, it, vi } from "vite-plus/test";
66

7-
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
7+
import {
8+
NativePrimaryColumnContext,
9+
NativeWorkspaceTabActivityContext,
10+
} from "../../native/v5-workspace-context";
811

912
// The Thread in the detail column is the focused route on iPad split view.
1013
vi.mock("@react-navigation/native", () => ({
1114
useNavigation: () => ({ isFocused: () => false }),
1215
}));
1316

1417
import {
18+
recordHomeFocus,
1519
recordHomeTransitionEnd,
1620
recordHomeTransitionStart,
1721
useAtomValueWhileVisible,
@@ -54,6 +58,18 @@ function setup() {
5458
),
5559
);
5660
},
61+
/** A phone has no primary column: Home is the root page of its tab's slot. */
62+
showHomeInTabSlot(active: boolean) {
63+
act(() =>
64+
root.render(
65+
<RegistryContext.Provider value={registry}>
66+
<NativeWorkspaceTabActivityContext value={{ active, isActive: () => active }}>
67+
<Probe />
68+
</NativeWorkspaceTabActivityContext>
69+
</RegistryContext.Provider>,
70+
),
71+
);
72+
},
5773
[Symbol.dispose]() {
5874
act(() => root.unmount());
5975
registry.dispose();
@@ -71,11 +87,51 @@ it("keeps the sidebar thread list live after switching tabs beside a focused Thr
7187

7288
// Chats → PRs → Chats: Chats' column will-appear, then the PRs column's did-disappear.
7389
act(() => {
74-
recordHomeTransitionEnd(true);
90+
recordHomeTransitionEnd(true, false);
7591
recordHomeTransitionStart(false);
76-
recordHomeTransitionEnd(true);
92+
recordHomeTransitionEnd(true, false);
7793
});
7894
act(() => home.registry.set(shellsAtom, 2));
7995

8096
expect(home.latest, "new thread shells reach the sidebar list").toBe(2);
8197
});
98+
99+
// Each phone tab slot shows its own copy of the Home route. PRs keeps Home focused; Settings
100+
// is a route of its own.
101+
it.each([
102+
{ tab: "PRs", homeFocusedUnderTab: true },
103+
{ tab: "Settings", homeFocusedUnderTab: false },
104+
])(
105+
"keeps the phone thread list live after a round trip through $tab",
106+
({ homeFocusedUnderTab }) => {
107+
using home = setup();
108+
recordHomeFocus();
109+
home.showHomeInTabSlot(true);
110+
act(() => home.registry.set(shellsAtom, 1));
111+
expect(home.latest).toBe(1);
112+
113+
// To the other tab: its slot will-appear, then the Chats slot's did-disappear.
114+
act(() => {
115+
recordHomeTransitionStart(false);
116+
recordHomeTransitionEnd(true, homeFocusedUnderTab);
117+
});
118+
home.showHomeInTabSlot(false);
119+
act(() => home.registry.set(shellsAtom, 2));
120+
expect(home.latest, "the list under another tab holds its rows").toBe(1);
121+
122+
// Back to Chats: its slot will-appear, then the other slot's did-disappear comes last.
123+
act(() => {
124+
recordHomeFocus();
125+
recordHomeTransitionStart(false);
126+
recordHomeTransitionEnd(true, true);
127+
});
128+
home.showHomeInTabSlot(true);
129+
act(() => home.registry.set(shellsAtom, 3));
130+
expect(home.latest, "a server rename reaches the list").toBe(3);
131+
132+
// A pushed Thread takes the focus and still stops the list.
133+
act(() => recordHomeTransitionEnd(true, false));
134+
act(() => home.registry.set(shellsAtom, 4));
135+
expect(home.latest, "the list under a Thread holds its rows").toBe(3);
136+
},
137+
);

‎apps/mobile/src/features/home/home-route-visibility.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { useNavigation } from "@react-navigation/native";
33
import { useContext, useRef, useSyncExternalStore } from "react";
44
import type { Atom } from "effect/reactivity";
55

6-
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
6+
import {
7+
NativePrimaryColumnContext,
8+
NativeWorkspaceTabActivityContext,
9+
} from "../../native/v5-workspace-context";
710

811
/**
912
* Home stays mounted under a pushed Thread, and native-stack never freezes the
@@ -34,8 +37,12 @@ export function recordHomeTransitionStart(closing: boolean): void {
3437
if (!closing) setHomeVisible(true);
3538
}
3639

37-
export function recordHomeTransitionEnd(closing: boolean): void {
38-
if (closing) setHomeVisible(false);
40+
/**
41+
* Each iOS tab slot shows its own copy of the Home route, and the slot a tab switch leaves
42+
* disappears last. So a disappear hides Home only when another route has the focus.
43+
*/
44+
export function recordHomeTransitionEnd(closing: boolean, homeFocused: boolean): void {
45+
if (closing && !homeFocused) setHomeVisible(false);
3946
}
4047

4148
/** Popping a sheet or a deep-linked route above Home has no appear event. */
@@ -46,10 +53,13 @@ export function recordHomeFocus(): void {
4653
export function useHomeRouteVisible(): boolean {
4754
const navigation = useNavigation();
4855
const primaryColumn = useContext(NativePrimaryColumnContext);
56+
const tabActive = useContext(NativeWorkspaceTabActivityContext)?.active ?? true;
4957
const visible = useSyncExternalStore(subscribeHomeVisibility, () => homeVisible);
5058
// Every tab slot's primary column reports to the one Home route, so a tab
5159
// switch can end on the leaving slot's disappear. Trust this column instead.
5260
if (primaryColumn) return primaryColumn.presented;
61+
// The store is true for the Home route of every tab; this list shows in one of them.
62+
if (!tabActive) return false;
5363
// Before Home's first navigation event: a cold deep link mounts Home under
5464
// its Thread without ever showing it.
5565
return visible ?? navigation.isFocused();

0 commit comments

Comments
 (0)