The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): sort pull request lists and timelines by time (#28391)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 07:28 UTC
64d70f8828e840ccd1f0d483499d96e9b42bc99e
6 files changed
+60
-18
apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx
+2
-2
@@ -21,7 +21,7 @@ import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/
21
import { AppBar } from "../../components/ui/AppBar";
22
import { Button } from "../../components/ui/Button";
23
import { GlassSurface } from "../../components/ui/GlassSurface";
24
-import { relativeTime } from "../../lib/time";
24
+import { compareTimestamps, relativeTime } from "../../lib/time";
25
import { composerPullRequests } from "../../state/pull-requests";
26
import { useAtomCommand } from "../../state/use-atom-command";
27
import { useEnvironmentQuery } from "../../state/query";
@@ -147,7 +147,7 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
147
...new Map(
148
[...extra, ...(thread?.comments ?? [])].map((comment) => [comment.id, comment]),
149
).values(),
150
- ].sort((left, right) => left.createdAt.localeCompare(right.createdAt));
150
+ ].sort((left, right) => compareTimestamps(left.createdAt, right.createdAt));
151
const scrollRef = useRef<ScrollViewInstance>(null);
152
const pendingTop = useRef<number | null>(null);
153
const positionedComment = useRef<string | null>(null);
apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+7
-9
@@ -142,15 +142,13 @@ function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityF
142
const filtered = result.data ? filterPullRequestActivity(result.data, filter) : null;
143
const rows = (() => {
144
if (!filtered) return [];
145
- const rows = pullRequestTimelineRows(filtered.activity, params, navigation, {
146
- permissions,
147
- onChanged: result.refresh,
148
- });
149
- if (filter.newestFirst) {
150
- const notice = rows.at(-1)?.key === "truncated" ? rows.pop() : undefined;
151
- rows.reverse();
152
- if (notice) rows.push(notice);
153
- }
145
+ const rows = pullRequestTimelineRows(
146
+ filtered.activity,
147
+ params,
148
+ navigation,
149
+ { permissions, onChanged: result.refresh },
150
+ filter.newestFirst,
151
+ );
152
if (!rows.length)
153
rows.push({
154
key: "empty",
apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx
+3
-2
@@ -17,7 +17,7 @@ import { Pressable, StyleSheet, View } from "react-native";
17
import { parseMarkdownDocument } from "../../lib/markdownDocument";
18
import { AppText as Text } from "../../components/ui/AppText";
19
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
20
-import { relativeTime } from "../../lib/time";
20
+import { byTimestamp, relativeTime } from "../../lib/time";
21
import { PullRequestAvatar } from "./PullRequestPresentation";
22
import { PullRequestMarkdown } from "./PullRequestMarkdown";
23
import { PullRequestCommentFooter } from "./PullRequestReactions";
@@ -218,6 +218,7 @@ export function pullRequestTimelineRows(
218
params: PullRequestParams,
219
navigation: Pick<NavigationProp<ReactNavigation.RootParamList>, "navigate" | "dispatch">,
220
actions: CommentActions,
221
+ newestFirst: boolean,
222
) {
223
const linkTarget = parsePullRequestAnchor(params.navigationUrl);
224
const threads = pullRequestConversationThreads(activity);
@@ -320,7 +321,7 @@ export function pullRequestTimelineRows(
321
</TimelineEvent>
322
),
323
})),
323
- ].sort((a, b) => a.date.localeCompare(b.date));
324
+ ].sort(byTimestamp(newestFirst));
325
if (activity.commentsTruncated || activity.reviewThreadsTruncated)
326
events.push({
327
key: "truncated",
apps/mobile/src/features/pull-requests/pullRequestList.ts
+5
-4
@@ -11,6 +11,7 @@ import {
11
type PullRequestListStatsInput,
12
} from "@t3tools/contracts";
13
import type { PullRequestListControls } from "../../persistence/mobile-preferences";
14
+import { compareTimestamps } from "../../lib/time";
15
16
export const PR_LIST_PAGE_SIZE = 30;
17
export type { PullRequestListControls } from "../../persistence/mobile-preferences";
@@ -242,7 +243,7 @@ export function mergePullRequestListEntries(
243
const held = entries.get(key);
244
if (!held || (entry.observedAt ?? 0) >= (held.observedAt ?? 0)) entries.set(key, entry);
245
}
245
- return [...entries.values()].sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
246
+ return [...entries.values()].sort((a, b) => compareTimestamps(b.updatedAt, a.updatedAt));
247
}
248
249
export interface PullRequestListPages {
@@ -455,10 +456,10 @@ export function filterPullRequestList<
456
}
457
return [...unique.values()].sort((a, b) =>
458
controls.sort === "created"
458
- ? b.createdAt.localeCompare(a.createdAt)
459
+ ? compareTimestamps(b.createdAt, a.createdAt)
460
: controls.sort === "oldest"
460
- ? a.updatedAt.localeCompare(b.updatedAt)
461
- : b.updatedAt.localeCompare(a.updatedAt),
461
+ ? compareTimestamps(a.updatedAt, b.updatedAt)
462
+ : compareTimestamps(b.updatedAt, a.updatedAt),
463
);
464
}
465
apps/mobile/src/lib/time.test.ts
+31
-1
@@ -1,9 +1,39 @@
1
import { describe, expect, it } from "vite-plus/test";
2
-import { msUntilRelativeTimeChange, relativeTime } from "./time";
2
+import { byTimestamp, compareTimestamps, msUntilRelativeTimeChange, relativeTime } from "./time";
3
4
const at = "2026-10-19T12:00:00.000Z";
5
const timestamp = Date.parse(at);
6
7
+describe("timestamp order", () => {
8
+ it("orders host timestamps by instant across offsets and fractional seconds, missing ones first", () => {
9
+ const dates = [
10
+ "2026-07-05T00:30:00.5Z",
11
+ "2026-07-05T01:00:00+02:00",
12
+ "",
13
+ "2026-07-05T00:30:00Z",
14
+ ];
15
+
16
+ expect(dates.toSorted(compareTimestamps)).toEqual([
17
+ "",
18
+ "2026-07-05T01:00:00+02:00",
19
+ "2026-07-05T00:30:00Z",
20
+ "2026-07-05T00:30:00.5Z",
21
+ ]);
22
+ });
23
+ it("keeps equal instants in input order whichever way it sorts", () => {
24
+ const rows = [
25
+ { id: "comment", date: "2026-07-05T00:30:00Z" },
26
+ { id: "commit", date: "2026-07-04T20:30:00-04:00" },
27
+ { id: "older", date: "2026-07-04T00:00:00Z" },
28
+ ];
29
+ const ids = (newestFirst: boolean) =>
30
+ rows.toSorted(byTimestamp(newestFirst)).map((row) => row.id);
31
+
32
+ expect(ids(false)).toEqual(["older", "comment", "commit"]);
33
+ expect(ids(true)).toEqual(["comment", "commit", "older"]);
34
+ });
35
+});
36
+
37
describe("relative time", () => {
38
it.each([
39
[59_999, "<1m", "1m"],
apps/mobile/src/lib/time.ts
+12
@@ -1,3 +1,15 @@
1
+// Host timestamps may carry UTC offsets or mixed fractions, so text order is not time order.
2
+export function compareTimestamps(left: string, right: string): number {
3
+ return (Date.parse(left) || 0) - (Date.parse(right) || 0);
4
+}
5
+
6
+export function byTimestamp(newestFirst: boolean) {
7
+ return (left: { readonly date: string }, right: { readonly date: string }) =>
8
+ newestFirst
9
+ ? compareTimestamps(right.date, left.date)
10
+ : compareTimestamps(left.date, right.date);
11
+}
12
+
13
export function relativeTime(input: string, nowMs: number = Date.now()): string {
14
const timestamp = Date.parse(input);
15
if (Number.isNaN(timestamp)) {