The best way to control Claude Code, Codex and more from any computer or phone
fix(web): older comments no longer reappear after refreshing an issue (#38489)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 18, 2026 at 09:30 UTC
b648395fa5afe9b017252436f7328c58b787d56e
8 files changed
+349
-100
apps/mobile/src/features/issues/IssueRouteScreen.tsx
+17
-45
@@ -1,7 +1,8 @@
1
+import { RegistryContext, useAtomValue } from "@effect/atom-react";
2
import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
3
import { issueEventSentence } from "@t3tools/client-runtime/issue-presentation";
4
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4
-import { prependIssueComments } from "@t3tools/client-runtime/state/issues";
5
+import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
6
import type {
7
IssueComment,
8
IssueEvent,
@@ -12,7 +13,7 @@ import type {
13
} from "@t3tools/contracts";
14
import { AsyncResult } from "effect/reactivity";
15
import { T, useGT, useMessages, Var } from "gt-react-native";
15
-import { useRef, useState } from "react";
16
+import { useContext, useState } from "react";
17
import { Linking, Platform, Pressable, Share, View } from "react-native";
18
import { KeyboardStickyView } from "react-native-keyboard-controller";
19
@@ -403,6 +404,9 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
404
const detailAtom = issueEnvironment.detail(target);
405
const detailQuery = useEnvironmentQuery(detailAtom);
406
const pullRefresh = usePullToRefresh(detailAtom);
407
+ const registry = useContext(RegistryContext);
408
+ const [pager] = useState(() => createIssueCommentPager(detailAtom));
409
+ const { comments, nextCursor, loadingOlder, canLoadOlder } = useAtomValue(pager.view);
410
const detail = detailQuery.data;
411
const issue: IssueSummary | null = detail ?? params.initialSummary ?? null;
412
const access = useIssueAccess(params, detail);
@@ -410,25 +414,13 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
414
const loadComments = useAtomCommand(issueEnvironment.comments, { reportFailure: false });
415
const postComment = useAtomCommand(issueEnvironment.comment, { reportFailure: false });
416
const setState = useAtomCommand(issueEnvironment.setState, { reportFailure: false });
413
- const [older, setOlder] = useState<{
414
- readonly seed: string | null;
415
- readonly comments: ReadonlyArray<IssueComment>;
416
- readonly cursor: string | null;
417
- } | null>(null);
418
- const [busy, setBusy] = useState<"older" | "comment" | "state" | null>(null);
417
+ const [busy, setBusy] = useState<"comment" | "state" | null>(null);
418
const [error, setError] = useState<string | null>(null);
419
const [composerHeight, setComposerHeight] = useState(0);
420
422
- // Older pages are tied to the cursor the detail was read with; a refreshed detail starts over.
423
- const olderComments = detail && older?.seed === detail.commentsCursor ? older.comments : [];
424
- const nextCursor = !detail
425
- ? null
426
- : older?.seed === detail.commentsCursor
427
- ? older.cursor
428
- : detail.commentsCursor;
421
const timeline = detail
422
? [
431
- ...prependIssueComments(detail.comments, olderComments).map((comment) => ({
423
+ ...comments.map((comment) => ({
424
key: `c:${comment.id}`,
425
at: comment.createdAt,
426
content: (
@@ -447,7 +439,7 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
439
kind: NonNullable<typeof busy>,
440
command: () => Promise<AsyncResult.AsyncResult<unknown, unknown>>,
441
) => {
450
- if (busy !== null) return false;
442
+ if (busy !== null || registry.get(pager.view).loadingOlder) return false;
443
setBusy(kind);
444
setError(null);
445
const failure = issueCommandError(await command());
@@ -457,28 +449,13 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
449
if (failure === null) refreshIssueLists(target.environmentId);
450
return failure === null;
451
};
460
- // Counts refreshes, so a page asked for before one is not laid over the read that follows it.
461
- const refreshes = useRef(0);
452
const loadOlder = async () => {
463
- if (!detail || nextCursor === null || busy !== null) return;
464
- const asked = refreshes.current;
465
- setBusy("older");
466
- setError(null);
467
- const result = await loadComments({
468
- ...target,
469
- input: { ...target.input, cursor: nextCursor },
470
- });
471
- setBusy(null);
472
- if (asked !== refreshes.current) return;
473
- if (AsyncResult.isFailure(result)) {
474
- setError(gt("Older comments could not be read."));
475
- return;
476
- }
477
- setOlder({
478
- seed: detail.commentsCursor,
479
- comments: prependIssueComments(olderComments, result.value.comments),
480
- cursor: result.value.nextCursor,
453
+ if (busy !== null) return;
454
+ const failure = await pager.loadOlder(registry, (cursor) => {
455
+ setError(null);
456
+ return loadComments({ ...target, input: { ...target.input, cursor } });
457
});
458
+ if (failure) setError(gt("Older comments could not be read."));
459
};
460
const submitComment = (body: string) =>
461
access?.comment === true
@@ -575,12 +552,7 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
552
refreshControl={
553
<RefreshControl
554
refreshing={pullRefresh.refreshing}
578
- onRefresh={() => {
579
- // Older pages are cached under the cursor, which a refresh can hand back unchanged.
580
- refreshes.current += 1;
581
- setOlder(null);
582
- pullRefresh.onRefresh();
583
- }}
555
+ onRefresh={() => void pager.refresh(registry, pullRefresh.onRefresh)}
556
/>
557
}
558
contentContainerStyle={{
@@ -652,8 +624,8 @@ function IssueRoute({ params }: { readonly params: IssueParams }) {
624
</PullRequestSectionHeading>
625
{nextCursor !== null ? (
626
<Button
655
- label={busy === "older" ? gt("Loading…") : gt("Load older comments")}
656
- disabled={busy !== null}
627
+ label={loadingOlder ? gt("Loading…") : gt("Load older comments")}
628
+ disabled={busy !== null || !canLoadOlder}
629
onPress={() => void loadOlder()}
630
/>
631
) : null}
apps/mobile/src/state/use-pull-to-refresh.ts
+2
-2
@@ -18,14 +18,14 @@ export function usePullToRefresh<A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A
18
[atom],
19
);
20
21
- const onRefresh = (beforeRefresh?: (signal: AbortSignal) => Promise<unknown>) => {
21
+ const onRefresh = async (beforeRefresh?: (signal: AbortSignal) => Promise<unknown>) => {
22
if (!atom || (request.current?.atom === atom && !request.current.controller.signal.aborted))
23
return;
24
request.current?.controller.abort();
25
const controller = new AbortController();
26
request.current = { atom, controller };
27
setRefreshingAtom(atom);
28
- void Promise.resolve()
28
+ await Promise.resolve()
29
.then(() => {
30
if (!controller.signal.aborted) return beforeRefresh?.(controller.signal);
31
})
apps/web/src/components/chat/RightPanelSurfaceContent.tsx
+1
-1
@@ -188,7 +188,7 @@ export function RightPanelSurfaceContent(props: {
188
}
189
return (
190
<IssueDetailPanel
191
- key={surface.id}
191
+ key={`${surface.environmentId ?? props.environmentId}:${surface.id}`}
192
environmentId={
193
(surface.environmentId as EnvironmentId | undefined) ?? props.environmentId
194
}
apps/web/src/components/issue/IssueDetailPanel.tsx
+14
-36
@@ -1,6 +1,6 @@
1
-import { useAtomValue } from "@effect/atom-react";
1
+import { RegistryContext, useAtomValue } from "@effect/atom-react";
2
import { issueEventSentence, issueWriteAccess } from "@t3tools/client-runtime/issue-presentation";
3
-import { prependIssueComments } from "@t3tools/client-runtime/state/issues";
3
+import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
4
import {
5
issueAssigneeHeld,
6
issueAssigneesAfterPicks,
@@ -38,7 +38,7 @@ import {
38
UsersIcon,
39
} from "lucide-react";
40
import { msg, T, useGT, useMessages, Var } from "gt-react";
41
-import { useState, type ReactNode } from "react";
41
+import { useContext, useState, type ReactNode } from "react";
42
43
import { RefreshIcon } from "~/components/ui/refresh-icon";
44
import { m } from "~/i18n/messages";
@@ -476,9 +476,11 @@ export function IssueDetailPanel({
476
}) {
477
const gt = useGT();
478
const messages = useMessages();
479
- const detailQuery = useEnvironmentQuery(
480
- issueEnvironment.detail({ environmentId, input: reference }),
481
- );
479
+ const detailAtom = issueEnvironment.detail({ environmentId, input: reference });
480
+ const detailQuery = useEnvironmentQuery(detailAtom);
481
+ const registry = useContext(RegistryContext);
482
+ const [pager] = useState(() => createIssueCommentPager(detailAtom));
483
+ const { comments, nextCursor, loadingOlder, canLoadOlder } = useAtomValue(pager.view);
484
const detail = detailQuery.data;
485
const canWrite = useAtomValue(issueEnvironment.comment.permissionAtom(environmentId));
486
const projects = useProjects();
@@ -486,13 +488,7 @@ export function IssueDetailPanel({
488
projects.find((p) => p.environmentId === environmentId && p.id === reference.projectId)
489
?.workspaceRoot ?? "";
490
489
- const [older, setOlder] = useState<{
490
- readonly seed: string | null;
491
- readonly comments: ReadonlyArray<IssueComment>;
492
- readonly cursor: string | null;
493
- } | null>(null);
491
const loadComments = useAtomCommand(issueEnvironment.comments, { reportFailure: false });
495
- const [loadingOlder, setLoadingOlder] = useState(false);
492
const update = useAtomCommand(issueEnvironment.update, { reportFailure: false });
493
const setState = useAtomCommand(issueEnvironment.setState, { reportFailure: false });
494
const [editing, setEditing] = useState<"title" | "body" | null>(null);
@@ -513,10 +509,6 @@ export function IssueDetailPanel({
509
return <IssueDetailGhost seed={listEntry} />;
510
}
511
516
- // Older pages are tied to the cursor the detail was read with; a refreshed detail starts over.
517
- const olderComments = older?.seed === detail.commentsCursor ? older.comments : [];
518
- const nextCursor = older?.seed === detail.commentsCursor ? older.cursor : detail.commentsCursor;
519
- const comments = prependIssueComments(detail.comments, olderComments);
512
const timeline: ReadonlyArray<TimelineItem> = [
513
...comments.map((c): TimelineItem => ({ kind: "comment", at: c.createdAt, comment: c })),
514
...detail.events.map((e): TimelineItem => ({ kind: "event", at: e.createdAt, event: e })),
@@ -534,22 +526,12 @@ export function IssueDetailPanel({
526
const currentState = issueStatePresentation(detail.state);
527
528
const loadOlder = async () => {
537
- if (nextCursor === null || loadingOlder) return;
538
- setLoadingOlder(true);
539
- const result = await loadComments({
540
- environmentId,
541
- input: { ...reference, cursor: nextCursor },
542
- });
543
- setLoadingOlder(false);
544
- if (result._tag === "Failure") {
529
+ const failure = await pager.loadOlder(registry, (cursor) =>
530
+ loadComments({ environmentId, input: { ...reference, cursor } }),
531
+ );
532
+ if (failure) {
533
toastManager.add({ type: "error", title: m(msg("Older comments could not be read")) });
546
- return;
534
}
548
- setOlder({
549
- seed: detail.commentsCursor,
550
- comments: prependIssueComments(olderComments, result.value.comments),
551
- cursor: result.value.nextCursor,
552
- });
535
};
536
537
const save = async (patch: { title?: string; body?: string }) => {
@@ -679,11 +661,7 @@ export function IssueDetailPanel({
661
variant="ghost"
662
aria-label={gt("Refresh issue")}
663
disabled={detailQuery.isPending}
682
- onClick={() => {
683
- // Older pages are cached under the cursor, which a refresh can hand back unchanged.
684
- setOlder(null);
685
- detailQuery.refresh();
686
- }}
664
+ onClick={() => void pager.refresh(registry, detailQuery.refresh)}
665
>
666
<RefreshIcon size="sm" refreshing={detailQuery.isPending} />
667
</Button>
@@ -904,7 +882,7 @@ export function IssueDetailPanel({
882
size="sm"
883
variant="outline"
884
className="self-start"
907
- disabled={loadingOlder}
885
+ disabled={!canLoadOlder}
886
onClick={() => void loadOlder()}
887
>
888
{loadingOlder ? <T>Loading…</T> : <T>Load older comments</T>}
apps/web/src/components/issue/IssuesPage.tsx
+1
-1
@@ -772,7 +772,7 @@ export function IssuesPage() {
772
>
773
{renderedSurface.kind === "issue" ? (
774
<IssueDetailPanel
775
- key={renderedSurface.id}
775
+ key={`${panelEnvironmentId}:${renderedSurface.id}`}
776
environmentId={panelEnvironmentId}
777
listEntry={panelListEntry}
778
reference={{
packages/client-runtime/src/state/issues.test.ts
+52
-14
@@ -3,17 +3,18 @@ import {
3
IssueTrackerKind,
4
ProjectId,
5
type IssueComment,
6
+ type IssueCommentsPage,
7
type IssueListEntry,
8
} from "@t3tools/contracts";
9
import * as Effect from "effect/Effect";
9
-import { Atom, AtomRegistry } from "effect/reactivity";
10
+import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
11
import { describe, expect, it } from "vite-plus/test";
12
13
import {
14
+ createIssueCommentPager,
15
createMergedIssueCandidatesAtoms,
16
issueEntryKey,
17
mergeIssueListPage,
16
- prependIssueComments,
18
} from "./issues.ts";
19
20
function entry(overrides: Partial<IssueListEntry> & { key: string }): IssueListEntry {
@@ -67,19 +68,56 @@ describe("mergeIssueListPage", () => {
68
});
69
});
70
70
-describe("prependIssueComments", () => {
71
- const comment = (id: string): IssueComment => ({
72
- id,
73
- author: null,
74
- body: id,
75
- createdAt: "2026-10-01T00:00:00.000Z",
76
- url: null,
77
- });
71
+const comment = (id: string): IssueComment => ({
72
+ id,
73
+ author: null,
74
+ body: id,
75
+ createdAt: "2026-10-01T00:00:00.000Z",
76
+ url: null,
77
+});
78
+
79
+describe("createIssueCommentPager", () => {
80
+ it("drops older pages on refresh, including one still loading, and pauses paging until it ends", async () => {
81
+ // The refreshed detail hands back the same cursor, so only the refresh itself can tell pages apart.
82
+ const detail = Atom.make(
83
+ AsyncResult.success({ comments: [comment("newest")], commentsCursor: "first-page" }),
84
+ );
85
+ const pager = createIssueCommentPager(detail);
86
+ const registry = AtomRegistry.make();
87
+ const unmount = registry.mount(pager.view);
88
+ const ids = () => registry.get(pager.view).comments.map(({ id }) => id);
89
+ const cursors: string[] = [];
90
+ const page = AsyncResult.success<IssueCommentsPage>({
91
+ comments: [comment("older"), comment("newest")],
92
+ nextCursor: "second-page",
93
+ });
94
+ const read = async (cursor: string) => {
95
+ cursors.push(cursor);
96
+ return page;
97
+ };
98
+ try {
99
+ await pager.loadOlder(registry, read);
100
+ expect(ids()).toEqual(["older", "newest"]);
101
79
- it("puts older comments first and drops ones already shown", () => {
80
- const current = [comment("c3"), comment("c4")];
81
- const older = [comment("c1"), comment("c2"), comment("c3")];
82
- expect(prependIssueComments(current, older).map((c) => c.id)).toEqual(["c1", "c2", "c3", "c4"]);
102
+ const pending = Promise.withResolvers<typeof page>();
103
+ const inFlight = pager.loadOlder(registry, () => pending.promise);
104
+ const refreshed = Promise.withResolvers<void>();
105
+ const refresh = pager.refresh(registry, () => refreshed.promise);
106
+ pending.resolve(page);
107
+ await inFlight;
108
+ expect(ids()).toEqual(["newest"]);
109
+
110
+ await pager.loadOlder(registry, read);
111
+ expect(registry.get(pager.view).canLoadOlder).toBe(false);
112
+ refreshed.resolve();
113
+ await refresh;
114
+ await pager.loadOlder(registry, read);
115
+ expect(cursors).toEqual(["first-page", "first-page"]);
116
+ expect(ids()).toEqual(["older", "newest"]);
117
+ } finally {
118
+ unmount();
119
+ registry.dispose();
120
+ }
121
});
122
});
123
packages/client-runtime/src/state/issues.ts
+87
-1
@@ -4,6 +4,8 @@ import {
4
type IssueAssigneeCandidate,
5
type IssueCandidates,
6
type IssueComment,
7
+ type IssueCommentsPage,
8
+ type IssueDetail,
9
type IssueLabelCandidate,
10
type IssueListEntry,
11
type IssueListInput,
@@ -17,6 +19,7 @@ import * as Option from "effect/Option";
19
import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity";
20
21
import {
22
+ type AtomCommandResult,
23
createAtomCommandScheduler,
24
createEnvironmentRpcCommand,
25
createEnvironmentRpcQueryAtomFamily,
@@ -49,7 +52,7 @@ export function mergeIssueListPage(
52
}
53
54
/** Older comments go in front: the detail carries the newest page and pages walk backwards. */
52
-export function prependIssueComments(
55
+function prependIssueComments(
56
current: ReadonlyArray<IssueComment>,
57
older: ReadonlyArray<IssueComment>,
58
): ReadonlyArray<IssueComment> {
@@ -58,6 +61,89 @@ export function prependIssueComments(
61
return [...older.filter((comment) => !seen.has(comment.id)), ...current];
62
}
63
64
+export function createIssueCommentPager<E>(
65
+ detailAtom: Atom.Atom<
66
+ AsyncResult.AsyncResult<Pick<IssueDetail, "comments" | "commentsCursor">, E>
67
+ >,
68
+) {
69
+ const state = Atom.make<{
70
+ readonly older: (IssueCommentsPage & { readonly seed: string }) | null;
71
+ readonly loadingOlder: boolean;
72
+ readonly refreshing: boolean;
73
+ readonly refreshes: number;
74
+ }>({ older: null, loadingOlder: false, refreshing: false, refreshes: 0 });
75
+ const page = Atom.make((get) => {
76
+ const detailResult = get(detailAtom);
77
+ const detail = AsyncResult.getOrElse(detailResult, () => null);
78
+ const current = get(state);
79
+ const seed = detail?.commentsCursor ?? null;
80
+ const older = current.older?.seed === seed ? current.older : null;
81
+ const nextCursor = older ? older.nextCursor : seed;
82
+ return {
83
+ comments: detail?.comments ?? [],
84
+ seed,
85
+ older,
86
+ nextCursor,
87
+ loadingOlder: current.loadingOlder,
88
+ unavailable: detailResult.waiting || current.refreshing || current.loadingOlder,
89
+ };
90
+ });
91
+ const view = Atom.make((get) => {
92
+ const { comments, older, nextCursor, loadingOlder, unavailable } = get(page);
93
+ return {
94
+ comments: prependIssueComments(comments, older?.comments ?? []),
95
+ nextCursor,
96
+ loadingOlder,
97
+ canLoadOlder: nextCursor !== null && !unavailable,
98
+ };
99
+ });
100
+
101
+ return {
102
+ view,
103
+ async refresh(registry: AtomRegistry.AtomRegistry, read: () => void | Promise<void>) {
104
+ const current = registry.get(state);
105
+ if (current.refreshing) return;
106
+ // The refreshed detail can return the same cursor, so invalidate outstanding pages explicitly.
107
+ registry.set(state, {
108
+ ...current,
109
+ older: null,
110
+ refreshing: true,
111
+ refreshes: current.refreshes + 1,
112
+ });
113
+ try {
114
+ await read();
115
+ } finally {
116
+ registry.set(state, { ...registry.get(state), refreshing: false });
117
+ }
118
+ },
119
+ async loadOlder(
120
+ registry: AtomRegistry.AtomRegistry,
121
+ read: (cursor: string) => Promise<AtomCommandResult<IssueCommentsPage, unknown>>,
122
+ ) {
123
+ const { seed, older, nextCursor, unavailable } = registry.get(page);
124
+ if (seed === null || nextCursor === null || unavailable) return;
125
+ const current = registry.get(state);
126
+ registry.set(state, { ...current, loadingOlder: true });
127
+ try {
128
+ const result = await read(nextCursor);
129
+ const latest = registry.get(state);
130
+ if (latest.refreshes !== current.refreshes) return;
131
+ if (result._tag === "Failure") return result;
132
+ registry.set(state, {
133
+ ...latest,
134
+ older: {
135
+ seed,
136
+ comments: prependIssueComments(older?.comments ?? [], result.value.comments),
137
+ nextCursor: result.value.nextCursor,
138
+ },
139
+ });
140
+ } finally {
141
+ registry.set(state, { ...registry.get(state), loadingOlder: false });
142
+ }
143
+ },
144
+ };
145
+}
146
+
147
/**
148
* Every read goes to a tracker API over the environment, so results are reused for a short while
149
* and refreshed explicitly. Mutations run serially per environment: changes to one issue are
scripts/scenarios/issues-refresh-discards-pending-older-comments.e2e.ts
new
+175
@@ -0,0 +1,175 @@
1
+/// <reference lib="dom" />
2
+import type { IssueComment, IssueCommentsPage, IssueDetail, IssueRef } from "@t3tools/contracts";
3
+import { expect } from "e2e";
4
+
5
+import { test, WEB } from "./t3.ts";
6
+
7
+test(
8
+ "A page requested before refreshing an issue does not restore old comments",
9
+ WEB,
10
+ async ({ t3, app, browser, screen }) => {
11
+ await t3.project("demo");
12
+ await browser.addInitScript(() => {
13
+ const pendingPage = new Promise<void>((resolve) => {
14
+ Object.assign(window, { releaseOldIssuePage: () => resolve() });
15
+ });
16
+ const comment = (id: string, body: string, day: string): IssueComment => ({
17
+ id,
18
+ body,
19
+ author: null,
20
+ createdAt: `2026-10-${day}T00:00:00.000Z`,
21
+ url: null,
22
+ });
23
+ let refreshed = false;
24
+ let pendingRefresh: Promise<void> | undefined;
25
+ Object.assign(window, {
26
+ armIssueRefresh: () => {
27
+ refreshed = true;
28
+ },
29
+ holdIssueRefresh: () => {
30
+ const { promise, resolve } = Promise.withResolvers<void>();
31
+ pendingRefresh = promise;
32
+ Object.assign(window, { releaseIssueRefresh: resolve });
33
+ },
34
+ });
35
+ // Keep the real socket for all other RPCs. Supply three pages of an unchanged GitHub
36
+ // comment history and hold the last page until the refreshed detail has rendered.
37
+ const send = WebSocket.prototype.send;
38
+ WebSocket.prototype.send = function (data) {
39
+ const request: {
40
+ _tag: string;
41
+ id: string;
42
+ tag: string;
43
+ payload: IssueRef & { cursor?: string };
44
+ } | null = typeof data === "string" ? JSON.parse(data) : null;
45
+ if (request?._tag !== "Request") return send.call(this, data);
46
+ const reply = (value: IssueDetail | IssueCommentsPage) =>
47
+ this.dispatchEvent(
48
+ new MessageEvent("message", {
49
+ data: JSON.stringify({
50
+ _tag: "Exit",
51
+ requestId: request.id,
52
+ exit: { _tag: "Success", value },
53
+ }),
54
+ }),
55
+ );
56
+ if (request.tag === "issues.detail") {
57
+ const { projectId, tracker, scope, key } = request.payload;
58
+ const detail: IssueDetail = {
59
+ projectId,
60
+ tracker,
61
+ scope,
62
+ key,
63
+ host: "github.com",
64
+ displayKey: "#42",
65
+ projectTitle: "demo",
66
+ title: refreshed ? "Pagination issue after refresh" : "Pagination issue",
67
+ body: "Comment history",
68
+ url: "https://github.com/example/demo/issues/42",
69
+ author: null,
70
+ state: { category: "open", name: "Open" },
71
+ createdAt: "2026-10-01T00:00:00.000Z",
72
+ updatedAt: "2026-10-04T00:00:00.000Z",
73
+ closedAt: null,
74
+ assignees: [],
75
+ labels: [],
76
+ commentCount: 201,
77
+ writable: false,
78
+ capabilities: {
79
+ create: false,
80
+ edit: false,
81
+ comment: false,
82
+ labels: false,
83
+ assignees: false,
84
+ reactions: false,
85
+ templates: false,
86
+ linkedPullRequests: false,
87
+ events: false,
88
+ search: true,
89
+ },
90
+ viewerPermissions: {
91
+ setState: false,
92
+ comment: false,
93
+ edit: false,
94
+ labels: false,
95
+ assignees: false,
96
+ },
97
+ states: [],
98
+ viewer: null,
99
+ comments: [comment("newest", "Newest comment", "04")],
100
+ commentsCursor: "first-older-page",
101
+ events: [],
102
+ linkedPullRequests: [],
103
+ };
104
+ if (pendingRefresh) {
105
+ void pendingRefresh.then(() => reply(detail));
106
+ pendingRefresh = undefined;
107
+ return;
108
+ }
109
+ queueMicrotask(() => reply(detail));
110
+ } else if (request.tag === "issues.comments") {
111
+ if (request.payload.cursor === "first-older-page") {
112
+ queueMicrotask(() =>
113
+ reply({
114
+ comments: [comment("older", "First older comment", "03")],
115
+ nextCursor: "last-page",
116
+ }),
117
+ );
118
+ } else if (request.payload.cursor === "last-page") {
119
+ void pendingPage.then(() =>
120
+ reply({
121
+ comments: [comment("oldest", "Oldest comment", "02")],
122
+ nextCursor: null,
123
+ }),
124
+ );
125
+ } else return send.call(this, data);
126
+ } else return send.call(this, data);
127
+ };
128
+ });
129
+
130
+ await t3.open("/issues?selectedProjectId=demo&tracker=github&scope=example/demo&key=42");
131
+ const loadOlder = screen.getByRole("button", "Load older comments", { exact: true });
132
+ // The issues route compiles on first open, which can outlast the 30 s action timeout.
133
+ await loadOlder.waitFor({ timeout: 60_000 });
134
+ await loadOlder.tap();
135
+ await screen.getByText("First older comment", { exact: true }).waitFor();
136
+ await loadOlder.tap();
137
+ const loading = screen.getByRole("button", "Loading…", { exact: true });
138
+ await loading.waitFor();
139
+ await browser.evaluate(() => {
140
+ (window as unknown as { armIssueRefresh: () => void }).armIssueRefresh();
141
+ return null;
142
+ });
143
+ await screen.getByRole("button", "Refresh issue", { exact: true }).tap();
144
+ await screen.getByText("Pagination issue after refresh", { exact: true }).waitFor();
145
+
146
+ await browser.evaluate(() => {
147
+ (window as unknown as { releaseOldIssuePage: () => void }).releaseOldIssuePage();
148
+ return null;
149
+ });
150
+ const activity = 'section[aria-label^="Activity"]';
151
+ await loading.waitFor({ state: "hidden" });
152
+ await browser.evaluate((selector) => {
153
+ document.querySelector(selector)?.scrollIntoView({ block: "start" });
154
+ return null;
155
+ }, activity);
156
+ await app.screenshot("activity-after-refresh-and-late-page");
157
+ await expect(browser.locator(activity)).not.toContainText("First older comment");
158
+
159
+ await browser.evaluate(() => {
160
+ (window as unknown as { holdIssueRefresh: () => void }).holdIssueRefresh();
161
+ return null;
162
+ });
163
+ const refresh = screen.getByRole("button", "Refresh issue", { exact: true });
164
+ await refresh.tap();
165
+ await expect(refresh).toBeDisabled();
166
+ await expect(loadOlder).toBeDisabled();
167
+ await browser.evaluate(() => {
168
+ (window as unknown as { releaseIssueRefresh: () => void }).releaseIssueRefresh();
169
+ return null;
170
+ });
171
+ await expect(loadOlder).toBeEnabled();
172
+ await loadOlder.tap();
173
+ await screen.getByText("First older comment", { exact: true }).waitFor();
174
+ },
175
+);