Registry Mirror
Skip to content

File tree

‎apps/mobile/src/features/issues/IssuesScreen.tsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ export function IssuesScreen(
183183
([, page]) => page.rereading === null && Object.keys(page.nextCursors).length > 0,
184184
);
185185
const moreFailure = [...held.values()].find((page) => page.moreFailure)?.moreFailure ?? null;
186+
const needsRetry = continuable.some(([, page]) => page.moreFailed);
186187
const loadMore = async (retry = false) => {
187188
// With nothing to continue, the spinner and new pages would only re-fire onEndReached forever.
188-
if (loading.current || continuable.length === 0 || (moreFailure !== null && !retry)) return;
189+
if (loading.current || continuable.length === 0 || (needsRetry && !retry)) return;
189190
loading.current = true;
190191
setLoadingMore(true);
191192
const loaded = await Promise.all(
@@ -471,9 +472,11 @@ export function IssuesScreen(
471472
accessibilityLabel={gt("Loading more issues")}
472473
/>
473474
</View>
474-
) : moreFailure ? (
475+
) : needsRetry ? (
475476
<View className="items-center gap-2 px-8 py-4">
476-
<Text className="text-xs text-foreground-muted">{moreFailure}</Text>
477+
{moreFailure ? (
478+
<Text className="text-xs text-foreground-muted">{moreFailure}</Text>
479+
) : null}
477480
<Button
478481
label={gt("Try again")}
479482
accessibilityLabel={gt("Retry loading more issues")}

‎packages/client-runtime/src/issueList.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ describe("continueIssuePage", () => {
6565
cursors,
6666
);
6767
expect(failed.errors.map((error) => error.message)).toEqual(["boom", "rate limited"]);
68+
// The server keeps a failed scope's cursor, so only a retry may ask for that page again.
69+
expect(failed.moreFailed).toBe(true);
6870
const retried = continueIssuePage(failed, answer({ entries: [entry({ key: "2" })] }), cursors);
6971
// The first page's failure has no cursor, so no continuation retried it.
7072
expect(retried.errors.map((error) => error.message)).toEqual(["boom"]);
73+
expect(retried.moreFailed).toBe(false);
7174
});
7275

7376
it("moves only the cursors asked for and keeps the other trackers' errors", () => {

‎packages/client-runtime/src/issueList.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface HeldIssuePage {
3333
readonly nextCursors: IssueListCursors;
3434
/** Why the last "Load more" failed, until a retry succeeds or a new first page arrives. */
3535
readonly moreFailure: string | null;
36+
/** The last "Load more" failed, whole or for a scope that keeps its cursor: only a retry asks again. */
37+
readonly moreFailed: boolean;
3638
/** How many pages "Load more" laid over the first page, per cursor. */
3739
readonly depth: Readonly<Record<string, number>>;
3840
/** A newer first page these rows are being read again under. */
@@ -52,6 +54,7 @@ function freshIssuePage(answer: IssueListResult, list: string): HeldIssuePage {
5254
moreErrors: [],
5355
nextCursors: answer.nextCursors,
5456
moreFailure: null,
57+
moreFailed: false,
5558
depth: {},
5659
rereading: null,
5760
};
@@ -145,7 +148,7 @@ export function continueIssuePage(
145148
next: IssueListResult | { readonly failure: string },
146149
asked: IssueListCursors = page.nextCursors,
147150
): HeldIssuePage {
148-
if ("failure" in next) return { ...page, moreFailure: next.failure };
151+
if ("failure" in next) return { ...page, moreFailure: next.failure, moreFailed: true };
149152
const moreErrors = page.moreErrors.filter((more) => !more.asked.some((key) => key in asked));
150153
if (next.errors.length > 0) moreErrors.push({ asked: Object.keys(asked), errors: next.errors });
151154
return {
@@ -159,6 +162,8 @@ export function continueIssuePage(
159162
...next.nextCursors,
160163
},
161164
moreFailure: null,
165+
// A scope that failed keeps its cursor, so the page failed even though the request answered.
166+
moreFailed: next.errors.length > 0,
162167
depth: {
163168
...page.depth,
164169
...Object.fromEntries(Object.keys(asked).map((key) => [key, (page.depth[key] ?? 0) + 1])),
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { expect } from "e2e";
2+
import * as Effect from "effect/Effect";
3+
import * as FileSystem from "effect/FileSystem";
4+
import * as Path from "effect/Path";
5+
6+
import { MOBILE, MOBILE_T3_HOME } from "../e2e.config.ts";
7+
import { run } from "./shell.ts";
8+
import { makeState, runPromise } from "./t3.ts";
9+
import { IOS, test } from "./t3-mobile.ts";
10+
11+
// Stand in for the Azure CLI upstream: 60 open work items, so the list's first 50 have a next
12+
// page. It counts each request for that page and refuses it while `next-page-fails` exists.
13+
const azureCli = String.raw`#!/usr/bin/env node
14+
import { appendFileSync, existsSync, readFileSync } from "node:fs";
15+
16+
const args = process.argv.slice(2);
17+
const argument = (name) => args[args.indexOf(name) + 1];
18+
const items = Array.from({ length: 60 }, (_, index) => {
19+
const id = 60 - index;
20+
return {
21+
id,
22+
url: "https://dev.azure.com/scenario/_apis/wit/workItems/" + id,
23+
fields: {
24+
"System.Title": "Release check " + id,
25+
"System.State": "Active",
26+
"System.TeamProject": "Release",
27+
"System.WorkItemType": "Task",
28+
"System.CreatedDate": "2026-10-01T00:00:00Z",
29+
"System.ChangedDate": new Date(Date.UTC(2026, 9, 2, 0, id)).toISOString(),
30+
},
31+
};
32+
});
33+
let output;
34+
switch (argument("--resource")) {
35+
case "workitemtypes":
36+
output = { value: [{ name: "Task", states: [
37+
{ name: "Active", category: "InProgress" },
38+
{ name: "Closed", category: "Completed" },
39+
] }] };
40+
break;
41+
case "wiql": {
42+
const { query } = JSON.parse(readFileSync(argument("--in-file"), "utf8"));
43+
const before = /\[System\.Id\] < (\d+)/.exec(query)?.[1];
44+
if (before !== undefined) {
45+
appendFileSync(new URL("./next-page-requests", import.meta.url), ".");
46+
if (existsSync(new URL("./next-page-fails", import.meta.url))) {
47+
console.error("ERROR: The request timed out.");
48+
process.exit(1);
49+
}
50+
}
51+
output = { workItems: items
52+
.filter((item) => before === undefined || item.id < Number(before))
53+
.map(({ id }) => ({ id })) };
54+
break;
55+
}
56+
case "workitemsbatch": {
57+
const { ids } = JSON.parse(readFileSync(argument("--in-file"), "utf8"));
58+
output = { value: items.filter(({ id }) => ids.includes(id)) };
59+
break;
60+
}
61+
default:
62+
if (args[0] === "repos" && args[1] === "show") {
63+
output = {
64+
name: "release",
65+
project: { name: "Release" },
66+
webUrl: "https://dev.azure.com/scenario/Release/_git/release",
67+
remoteUrl: "https://dev.azure.com/scenario/Release/_git/release",
68+
sshUrl: "git@ssh.dev.azure.com:v3/scenario/Release/release",
69+
};
70+
break;
71+
}
72+
process.exit(1);
73+
}
74+
console.log(JSON.stringify(output));
75+
`;
76+
77+
test(
78+
"A failed next page of issues waits for Try again instead of loading again on scroll",
79+
IOS,
80+
async ({ t3, app, screen }) => {
81+
const workspace = await t3.project("demo");
82+
const { repository, fails, requests } = await runPromise(
83+
Effect.gen(function* () {
84+
const path = yield* Path.Path;
85+
const fs = yield* FileSystem.FileSystem;
86+
const bin = path.join(MOBILE_T3_HOME, "bin");
87+
yield* fs.writeFileString(path.join(bin, "az"), azureCli);
88+
yield* fs.chmod(path.join(bin, "az"), 0o755);
89+
yield* fs.writeFileString(path.join(bin, "next-page-fails"), "");
90+
yield* fs.writeFileString(path.join(bin, "next-page-requests"), "");
91+
return {
92+
repository: path.join(MOBILE_T3_HOME, "release"),
93+
fails: path.join(bin, "next-page-fails"),
94+
requests: path.join(bin, "next-page-requests"),
95+
};
96+
}),
97+
);
98+
const nextPageRequests = () =>
99+
runPromise(
100+
Effect.flatMap(FileSystem.FileSystem, (fs) => fs.readFileString(requests)).pipe(
101+
Effect.map((asked) => asked.length),
102+
),
103+
);
104+
await runPromise(run("git", ["clone", "--quiet", workspace, repository]));
105+
await runPromise(
106+
run(
107+
"git",
108+
["remote", "set-url", "origin", "https://dev.azure.com/scenario/Release/_git/release"],
109+
{ cwd: repository },
110+
),
111+
);
112+
const primary = makeState(MOBILE_T3_HOME, { T3CODE_PORT: String(MOBILE.serverPort) });
113+
await runPromise(primary.cli(["project", "add", repository, "--title", "Release"]));
114+
try {
115+
// A local simulator keeps the last run's pairing.
116+
await app.clearState().catch(() => {});
117+
await t3.open();
118+
// Pull requests and issues share one tab; its title switches between them.
119+
await screen.getByRole("tab", "PRs").tap({ timeout: 120_000 });
120+
await screen.getByLabel("Pull requests, switch list").tap();
121+
await screen.getByRole("button", "Issues").tap();
122+
await screen.getByRole("button", /Release check 60,/).waitFor({ timeout: 60_000 });
123+
124+
const lastOfFirstPage = screen.getByRole("button", /Release check 11,/);
125+
const toTheEnd = async () => {
126+
await screen.scrollUntilVisible(lastOfFirstPage, { direction: "down", momentum: "fast" });
127+
await screen.swipe({ direction: "down" });
128+
};
129+
const retry = screen.getByRole("button", "Retry loading more issues");
130+
await toTheEnd();
131+
// Reaching the end asks for the next page, which fails.
132+
await expect(retry).toBeVisible();
133+
expect(await nextPageRequests()).toBe(1);
134+
await app.screenshot("end-of-the-list-after-the-next-page-failed");
135+
136+
// Back toward the top and to the end again, without a tap.
137+
await screen.swipe({ direction: "up" });
138+
await screen.swipe({ direction: "up" });
139+
await app.screenshot("back-toward-the-top");
140+
await toTheEnd();
141+
await app.screenshot("end-of-the-list-again");
142+
await expect(retry).toBeVisible();
143+
expect(await nextPageRequests()).toBe(1);
144+
145+
await runPromise(Effect.flatMap(FileSystem.FileSystem, (fs) => fs.remove(fails)));
146+
await retry.tap();
147+
await expect(screen.getByRole("button", /Release check 10,/)).toBeVisible();
148+
await app.screenshot("next-page-after-try-again");
149+
} finally {
150+
await runPromise(primary.cli(["project", "remove", repository, "--force"]));
151+
}
152+
},
153+
);

0 commit comments

Comments
 (0)