The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): relative-time labels keep counting on archive and pull request screens (#22151)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com>
Victor Vogel committed
Oct 30, 2026 at 20:23 UTC
ee2800e776c3055f6cfed5c5bd06d2c96680be55
7 files changed
+86
-11
apps/mobile/src/components/RelativeTime.tsx
new
+21
@@ -0,0 +1,21 @@
1
+import { useSyncExternalStore } from "react";
2
+import { msUntilRelativeTimeChange, relativeTime } from "../lib/time";
3
+
4
+// The React Compiler caches inline relativeTime calls on the timestamp alone.
5
+export function RelativeTime(props: { timestamp: string }) {
6
+ const subscribe = (onChange: () => void) => {
7
+ let timer: ReturnType<typeof setTimeout> | undefined;
8
+ const schedule = () => {
9
+ const delayMs = msUntilRelativeTimeChange(props.timestamp);
10
+ if (delayMs === null) return;
11
+ timer = setTimeout(() => {
12
+ onChange();
13
+ schedule();
14
+ }, delayMs);
15
+ };
16
+ schedule();
17
+ return () => clearTimeout(timer);
18
+ };
19
+ const getSnapshot = () => relativeTime(props.timestamp);
20
+ return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
21
+}
apps/mobile/src/features/archive/ArchivedThreadsScreen.tsx
+2
-3
@@ -24,7 +24,7 @@ import { AppText as Text } from "../../components/ui/AppText";
24
import { EmptyState } from "../../components/ui/EmptyState";
25
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
26
import { ProjectFavicon } from "../../components/ProjectFavicon";
27
-import { relativeTime } from "../../lib/time";
27
+import { RelativeTime } from "../../components/RelativeTime";
28
import { useUniwindTheme } from "../../lib/useUniwindTheme";
29
import { useServerConfigs } from "../../state/entities";
30
import { useEnvironmentScope } from "../../state/session";
@@ -193,7 +193,6 @@ function ArchivedThreadRow(props: {
193
props.thread.environmentId,
194
AuthOrchestrationOperateScope,
195
);
196
- const timestamp = relativeTime(props.thread.archivedAt ?? props.thread.updatedAt);
196
const subtitle = [props.environmentLabel, props.thread.branch].filter((part): part is string =>
197
Boolean(part),
198
);
@@ -219,7 +218,7 @@ function ArchivedThreadRow(props: {
218
{props.thread.title}
219
</Text>
220
<Text className="min-w-[30px] text-right text-xs tabular-nums text-foreground-tertiary">
222
- {timestamp}
221
+ <RelativeTime timestamp={props.thread.archivedAt ?? props.thread.updatedAt} />
222
</Text>
223
</View>
224
{subtitle.length > 0 ? (
apps/mobile/src/features/pull-requests/PullRequestListRow.tsx
+2
-2
@@ -9,7 +9,7 @@ import { SymbolView } from "../../components/ui/AppSymbol";
9
import { Menu } from "../../components/ui/Menu";
10
import type { MenuProps } from "../../components/ui/Menu.types";
11
import { cn } from "../../lib/cn";
12
-import { relativeTime } from "../../lib/time";
12
+import { RelativeTime } from "../../components/RelativeTime";
13
import {
14
selectedThreadRowColors,
15
THREAD_LIST_V2_SIDEBAR_ROW_STYLE,
@@ -132,7 +132,7 @@ export const PullRequestListRow = memo(
132
</View>
133
) : null}
134
<Text className={cn("text-2xs tabular-nums", tertiaryForeground)}>
135
- {relativeTime(item.updatedAt)}
135
+ <RelativeTime timestamp={item.updatedAt} />
136
</Text>
137
</View>
138
<Text
apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+2
-2
@@ -74,7 +74,7 @@ import { useAndroidWorkspaceBack } from "../workspace/useAndroidWorkspaceNavigat
74
import { EmptyState } from "../../components/ui/EmptyState";
75
import { SegmentedControl } from "../../components/ui/SegmentedControl";
76
import { SymbolView } from "../../components/ui/AppSymbol";
77
-import { relativeTime } from "../../lib/time";
77
+import { RelativeTime } from "../../components/RelativeTime";
78
import { NativeStackScreenOptions } from "../../native/StackHeader";
79
import { usePullRequestConnected } from "./usePullRequestConnected";
80
import { usePullRequestLiveChecks } from "./usePullRequestLiveChecks";
@@ -213,7 +213,7 @@ function PullRequestIdentity(props: {
213
{pr.author?.login ?? "Unknown author"}
214
</Text>
215
<Text className="shrink text-right text-2xs text-foreground-muted" numberOfLines={1}>
216
- Updated {relativeTime(pr.updatedAt)} ago
216
+ Updated <RelativeTime timestamp={pr.updatedAt} /> ago
217
</Text>
218
</View>
219
<View className="flex-row items-start gap-1.5">
apps/mobile/src/features/threads/LinkedPullRequestList.tsx
+2
-2
@@ -17,7 +17,7 @@ import { AppText as Text } from "../../components/ui/AppText";
17
import * as Dialog from "../../components/ui/Dialog";
18
import { Menu } from "../../components/ui/Menu";
19
import { cn } from "../../lib/cn";
20
-import { relativeTime } from "../../lib/time";
20
+import { RelativeTime } from "../../components/RelativeTime";
21
import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
22
import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
23
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
@@ -150,7 +150,7 @@ export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
150
) : null}
151
{snapshot?.updatedAt ? (
152
<Text className="text-2xs tabular-nums text-foreground-tertiary">
153
- {relativeTime(snapshot.updatedAt)}
153
+ <RelativeTime timestamp={snapshot.updatedAt} />
154
</Text>
155
) : null}
156
</View>
apps/mobile/src/lib/time.test.ts
new
+41
@@ -0,0 +1,41 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+import { msUntilRelativeTimeChange, relativeTime } from "./time";
3
+
4
+const at = "2026-10-19T12:00:00.000Z";
5
+const timestamp = Date.parse(at);
6
+
7
+describe("relative time", () => {
8
+ it.each([
9
+ [59_999, "<1m", "1m"],
10
+ [119_999, "1m", "2m"],
11
+ [3_599_999, "59m", "1h"],
12
+ [7_199_999, "1h", "2h"],
13
+ [86_399_999, "23h", "1d"],
14
+ [172_799_999, "1d", "2d"],
15
+ ] as const)("updates at the next boundary after %i ms", (elapsed, before, after) => {
16
+ const nowMs = timestamp + elapsed;
17
+ expect(relativeTime(at, nowMs)).toBe(before);
18
+ expect(msUntilRelativeTimeChange(at, nowMs)).toBe(1);
19
+ expect(relativeTime(at, nowMs + 1)).toBe(after);
20
+ });
21
+
22
+ it.each([
23
+ [0, 60_000],
24
+ [60_000, 60_000],
25
+ [3_600_000, 3_600_000],
26
+ [86_400_000, 86_400_000],
27
+ ])("waits a full label interval at %i ms", (elapsed, delay) => {
28
+ expect(msUntilRelativeTimeChange(at, timestamp + elapsed)).toBe(delay);
29
+ });
30
+
31
+ it("keeps invalid timestamps static", () => {
32
+ expect(relativeTime("invalid", timestamp)).toBe("<1m");
33
+ expect(msUntilRelativeTimeChange("invalid", timestamp)).toBeNull();
34
+ });
35
+
36
+ it("waits until a future timestamp is a minute old, with bounded timers", () => {
37
+ expect(relativeTime(at, timestamp - 30_000)).toBe("<1m");
38
+ expect(msUntilRelativeTimeChange(at, timestamp - 30_000)).toBe(90_000);
39
+ expect(msUntilRelativeTimeChange(at, timestamp - 30 * 86_400_000)).toBe(86_400_000);
40
+ });
41
+});
apps/mobile/src/lib/time.ts
+16
-2
@@ -1,10 +1,10 @@
1
-export function relativeTime(input: string): string {
1
+export function relativeTime(input: string, nowMs: number = Date.now()): string {
2
const timestamp = Date.parse(input);
3
if (Number.isNaN(timestamp)) {
4
return "<1m";
5
}
6
7
- const deltaSeconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1000));
7
+ const deltaSeconds = Math.max(0, Math.floor((nowMs - timestamp) / 1000));
8
if (deltaSeconds < 60) return "<1m";
9
10
const deltaMinutes = Math.floor(deltaSeconds / 60);
@@ -16,3 +16,17 @@ export function relativeTime(input: string): string {
16
const deltaDays = Math.floor(deltaHours / 24);
17
return `${deltaDays}d`;
18
}
19
+
20
+/** Milliseconds until the relative-time label next changes. */
21
+export function msUntilRelativeTimeChange(
22
+ input: string,
23
+ nowMs: number = Date.now(),
24
+): number | null {
25
+ const timestamp = Date.parse(input);
26
+ if (Number.isNaN(timestamp)) return null;
27
+ const elapsedMs = Math.max(0, nowMs - timestamp);
28
+ const unitMs = elapsedMs < 3_600_000 ? 60_000 : elapsedMs < 86_400_000 ? 3_600_000 : 86_400_000;
29
+ const nextChangeMs = timestamp + (Math.floor(elapsedMs / unitMs) + 1) * unitMs;
30
+ // Far-future timestamps must not overflow setTimeout's signed 32-bit delay.
31
+ return Math.min(nextChangeMs - nowMs, 86_400_000);
32
+}