The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 10:45 UTC
fix(mobile): keep refresh errors out of the load-more footer (#23594)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 30, 2026 at 16:46 UTC
e5559038165337caaf84ec162e3343b6c25120da
3 files changed
+133
-3
apps/mobile/src/features/pull-requests/usePullRequestList.test.tsx
new
+130
@@ -0,0 +1,130 @@
1
+import { RegistryContext } from "@effect/atom-react";
2
+import {
3
+ EnvironmentId,
4
+ type PullRequestListInput,
5
+ type PullRequestListResult,
6
+} from "@t3tools/contracts";
7
+import { AtomRegistry } from "effect/reactivity";
8
+import { act, useLayoutEffect } from "react";
9
+import { createRoot } from "react-dom/client";
10
+import { expect, it, vi } from "vite-plus/test";
11
+
12
+const mocks = vi.hoisted(() => ({ failPage: false }));
13
+
14
+vi.mock("../../connection/catalog", async () => {
15
+ const { Atom } = await import("effect/reactivity");
16
+ return {
17
+ environmentCatalog: {
18
+ sessionGenerationAtom: Atom.family((_environmentId: string) => Atom.make(0)),
19
+ },
20
+ };
21
+});
22
+
23
+vi.mock("../../state/pull-requests", async () => {
24
+ const { AsyncResult, Atom } = await import("effect/reactivity");
25
+ const Effect = await import("effect/Effect");
26
+ const page = (nextCursors: PullRequestListResult["nextCursors"]): PullRequestListResult => ({
27
+ entries: [],
28
+ nextCursors,
29
+ truncated: false,
30
+ viewers: {},
31
+ providers: [],
32
+ errors: [],
33
+ });
34
+ const list = Atom.family((key: string) => {
35
+ const target: { environmentId: string; input: PullRequestListInput } = JSON.parse(key);
36
+ const response = page(target.input.cursors ? {} : { "github.com org/repo": "next" });
37
+ return Atom.make(
38
+ Effect.suspend(() => {
39
+ if (target.environmentId === "offline")
40
+ return Effect.fail(new Error("Environment is not connected."));
41
+ if (target.input.cursors && mocks.failPage) return Effect.fail(new Error("Page failed."));
42
+ return Effect.succeed(response);
43
+ }),
44
+ );
45
+ });
46
+ const { pullRequestListHead } = await import("./pullRequestList");
47
+ const pages = Atom.family((_key: string) =>
48
+ Atom.make<ReturnType<typeof pullRequestListHead> | null>(null),
49
+ );
50
+ return {
51
+ pullRequestListPagesKey: (target: unknown) => JSON.stringify(target),
52
+ pullRequestListPagesFamily: pages,
53
+ pullRequestListStatsFamily: Atom.family((_key: string) => Atom.make(new Map())),
54
+ composerPullRequests: {
55
+ list: (target: unknown) => list(JSON.stringify(target)),
56
+ listStats: Atom.family(() => Atom.make(AsyncResult.success({ stats: [] }))),
57
+ invalidate: {
58
+ run: async () => AsyncResult.success({}),
59
+ },
60
+ },
61
+ };
62
+});
63
+
64
+import { usePullRequestList } from "./usePullRequestList";
65
+
66
+function setup(ids: readonly string[]) {
67
+ mocks.failPage = false;
68
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
69
+ const registry = AtomRegistry.make();
70
+ const targets = ids.map((id) => ({
71
+ environmentId: EnvironmentId.make(id),
72
+ input: { state: "open" as const },
73
+ }));
74
+ let latest: ReturnType<typeof usePullRequestList>;
75
+ function Probe() {
76
+ const result = usePullRequestList(targets);
77
+ useLayoutEffect(() => {
78
+ latest = result;
79
+ });
80
+ return null;
81
+ }
82
+ const root = createRoot(document.createElement("div"));
83
+ act(() => {
84
+ root.render(
85
+ <RegistryContext.Provider value={registry}>
86
+ <Probe />
87
+ </RegistryContext.Provider>,
88
+ );
89
+ });
90
+ return {
91
+ get latest() {
92
+ return latest;
93
+ },
94
+ [Symbol.dispose]() {
95
+ act(() => root.unmount());
96
+ registry.dispose();
97
+ },
98
+ };
99
+}
100
+
101
+it("keeps a refresh failure in the source errors and allows healthy pagination", async () => {
102
+ using probe = setup(["healthy", "offline"]);
103
+ await act(async () => probe.latest.onRefresh());
104
+ expect(probe.latest.data.errors.map((error) => error.message)).toEqual([
105
+ "Environment is not connected.",
106
+ ]);
107
+ expect(probe.latest.refreshing).toBe(false);
108
+ expect(probe.latest.loadMoreError).toBeNull();
109
+
110
+ await act(async () => probe.latest.loadMore());
111
+ expect(probe.latest.continued).toBe(true);
112
+ expect(probe.latest.hasMore).toBe(false);
113
+ expect(probe.latest.loadMoreError).toBeNull();
114
+});
115
+
116
+it("keeps load-more failures retryable", async () => {
117
+ using probe = setup(["healthy"]);
118
+ await act(async () => probe.latest.onRefresh());
119
+ mocks.failPage = true;
120
+ await act(async () => probe.latest.loadMore());
121
+ expect(probe.latest.loadMoreError).toBe("Page failed.");
122
+ expect(probe.latest.hasMore).toBe(true);
123
+ expect(probe.latest.continued).toBe(false);
124
+
125
+ mocks.failPage = false;
126
+ await act(async () => probe.latest.loadMore(true));
127
+ expect(probe.latest.loadMoreError).toBeNull();
128
+ expect(probe.latest.hasMore).toBe(false);
129
+ expect(probe.latest.continued).toBe(true);
130
+});
apps/mobile/src/features/pull-requests/usePullRequestList.ts
+2
-3
@@ -162,8 +162,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
162
const refreshAtom = refreshLoadFamily(scopeKey);
163
const page = useAtomValue(pageAtom);
164
const refresh = useAtomValue(refreshAtom);
165
- // Starting one kind of load clears the other, so at most one holds an error.
166
- const loadError = settledError(refresh) ?? settledError(page);
165
+ const loadError = settledError(page);
166
167
// A page or refresh asked for while an environment was unreachable fails at once, and its
168
// error stops loading on scroll. Once it is back, ask for the page again; a refresh's error is
@@ -184,7 +183,7 @@ export function usePullRequestList(targets: readonly ListTarget[]) {
183
const pageResult = registry.get(pageAtom);
184
const refreshResult = registry.get(refreshAtom);
185
if (pageResult.waiting || refreshResult.waiting) return;
187
- if (!retry && (settledError(refreshResult) ?? settledError(pageResult))) return;
186
+ if (!retry && settledError(pageResult)) return;
187
if (!continuations(registry, targets).length) return;
188
registry.set(refreshAtom, Atom.Reset);
189
registry.set(pageAtom, retry);
apps/mobile/vite.config.ts
+1
@@ -16,6 +16,7 @@ const reactTests = [
16
"src/features/pull-requests/usePullRequestDiff.test.tsx",
17
"src/components/ProjectFavicon.test.tsx",
18
"src/components/ui/Dialog.android.test.tsx",
19
+ "src/features/pull-requests/usePullRequestList.test.tsx",
20
"src/features/files/ZipArchiveView.test.tsx",
21
"src/features/pull-requests/guide/useReviewGuide.test.tsx",
22
"src/features/settings/SettingsServerControlsRouteScreen.test.tsx",