TypeScript
fix(web): sort pull request lists and timelines by time (#23588)
Victor Vogel5884d434813c
diff --git a/apps/web/src/components/pullRequest/PullRequestsPage.tsx b/apps/web/src/components/pullRequest/PullRequestsPage.tsxindex 359d86b4fc7..1b3d1bc74c1 100644--- a/apps/web/src/components/pullRequest/PullRequestsPage.tsx+++ b/apps/web/src/components/pullRequest/PullRequestsPage.tsx@@ -43,6 +43,7 @@ import {pullRequestOverrideAfterAction,reusePullRequestEntries,settlePullRequestOverrides,+ comparePullRequestsByRecency,largestPullRequestReadCount,} from "./pullRequestList.logic";import {@@ -564,7 +565,7 @@ export function PullRequestsPage() {const held = new Set(ordered.entries.map(pullRequestEntryKey));const arrived = answered.entries.filter((entry) => !held.has(pullRequestEntryKey(entry)));const appended = rankPullRequestMatches(- arrived.toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt)),+ arrived.toSorted(comparePullRequestsByRecency),sentParsed.text,);setOrdered({ key: filterKey, source: answered, entries: [...ordered.entries, ...appended] });diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.tsindex 8f316f5f4c7..7c1cc47883f 100644--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts@@ -316,6 +316,19 @@ describe("review verdicts", () => {});describe("pull request timeline", () => {+ it("orders host timestamps by instant across offsets and fractional seconds", () => {+ const events = buildPullRequestTimeline({+ ...TIMELINE_SOURCE,+ createdAt: "2026-07-05T01:00:00+02:00",+ commits: [{ oid: "commit", messageHeadline: "", committedDate: "2026-07-05T00:30:00Z" }],+ comments: [{ ...TIMELINE_SOURCE.comments[0]!, createdAt: "2026-07-05T00:30:00.5Z" }],+ mergedAt: null,+ closedAt: null,+ });++ expect(events.map((event) => event.id)).toEqual(["c1", "commit", "created"]);+ });+it("drops a body that is nothing but a bot's HTML comment, and keeps one that says more", () => {const events = buildPullRequestTimeline({...TIMELINE_SOURCE,diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.tsindex f422dfbc0e3..2a7dc7151b9 100644--- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts+++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts@@ -753,7 +753,7 @@ export function buildPullRequestTimeline(},]: []),- ].toSorted((left, right) => right.at.localeCompare(left.at));+ ].toSorted((left, right) => (instant(right.at) || 0) - (instant(left.at) || 0));}const FINDING_LIMIT = 20;diff --git a/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestList.logic.test.tsindex c6c10c7a4c3..1ed83fba3dd 100644--- a/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts+++ b/apps/web/src/components/pullRequest/pullRequestList.logic.test.ts@@ -406,6 +406,20 @@ describe("merging the environments' own listings", () => {...overrides,}) as Parameters<typeof mergePullRequestLists>[0][number][1];+ it("orders host timestamps by instant across offsets and fractional seconds", () => {+ const entries = [+ entry({ number: 1, updatedAt: "2026-07-05T01:00:00+02:00" }),+ entry({ number: 2, updatedAt: "2026-07-05T00:30:00Z" }),+ entry({ number: 3, updatedAt: "2026-07-05T00:30:00.5Z" }),+ ];+ const merged = mergePullRequestLists([+ [ENV_1, answer({ entries: entries.slice(0, 2) })],+ [ENV_2, answer({ entries: entries.slice(2) })],+ ]);++ expect(merged?.entries.map((row) => row.number)).toEqual([3, 2, 1]);+ });+it("tags every row with the environment that read it, newest first", () => {const merged = mergePullRequestLists([[ENV_1, answer({ entries: [entry({ number: 1, updatedAt: "2026-07-01T00:00:00Z" })] })],diff --git a/apps/web/src/components/pullRequest/pullRequestList.logic.ts b/apps/web/src/components/pullRequest/pullRequestList.logic.tsindex 33288085f85..b3e447a82e5 100644--- a/apps/web/src/components/pullRequest/pullRequestList.logic.ts+++ b/apps/web/src/components/pullRequest/pullRequestList.logic.ts@@ -469,11 +469,16 @@ export function partitionPullRequestsWithPriority<Entry extends PullRequestListEothers.push(entry);}}- const byRecency = (left: Entry, right: Entry) => right.updatedAt.localeCompare(left.updatedAt);return ([- { key: "authored", entries: [...authoredByKey.values()].toSorted(byRecency) },- { key: "reviewRequested", entries: [...reviewByKey.values()].toSorted(byRecency) },+ {+ key: "authored",+ entries: [...authoredByKey.values()].toSorted(comparePullRequestsByRecency),+ },+ {+ key: "reviewRequested",+ entries: [...reviewByKey.values()].toSorted(comparePullRequestsByRecency),+ },{ key: "others", entries: others },] as const)@@ -564,7 +569,7 @@ export function mergePullRequestLists(return {viewers,providers: [...providers.values()],- entries: entries.toSorted((left, right) => right.updatedAt.localeCompare(left.updatedAt)),+ entries: entries.toSorted(comparePullRequestsByRecency),errors,truncated,nextCursors,@@ -660,7 +665,7 @@ export function rankPullRequestMatches<Entry extends PullRequestListEntry>(if (query.trim().length === 0) return entries;return entries.toSorted((left, right) => {const byScore = scorePullRequestMatch(right, query) - scorePullRequestMatch(left, query);- return byScore !== 0 ? byScore : right.updatedAt.localeCompare(left.updatedAt);+ return byScore !== 0 ? byScore : comparePullRequestsByRecency(left, right);});}@@ -681,24 +686,29 @@ export function rankPullRequestsByMergeReadiness<Entry extends PullRequestListEnif (byTier !== 0) return byTier;const measured = Number(hasMeasuredSize(right)) - Number(hasMeasuredSize(left));const sized = left.additions + left.deletions - (right.additions + right.deletions);- return measured || sized || right.updatedAt.localeCompare(left.updatedAt);+ return measured || sized || comparePullRequestsByRecency(left, right);});}+export function comparePullRequestsByRecency(+ left: PullRequestListEntry,+ right: PullRequestListEntry,+) {+ const leftUpdated = toSortableTimestamp(left.updatedAt);+ const rightUpdated = toSortableTimestamp(right.updatedAt);+ const measured = Number(leftUpdated === null) - Number(rightUpdated === null);+ if (measured !== 0) return measured;+ if (leftUpdated === null || rightUpdated === null) return 0;+ return rightUpdated - leftUpdated;+}+function rankByTierThenRecency<Entry extends PullRequestListEntry>(entries: ReadonlyArray<Entry>,tier: (entry: Entry) => number,): ReadonlyArray<Entry> {- const timestamp = (entry: Entry) => toSortableTimestamp(entry.updatedAt);return entries.toSorted((left, right) => {const byTier = tier(left) - tier(right);- if (byTier !== 0) return byTier;- const leftUpdated = timestamp(left);- const rightUpdated = timestamp(right);- const measured = Number(leftUpdated === null) - Number(rightUpdated === null);- if (measured !== 0) return measured;- if (leftUpdated === null || rightUpdated === null) return 0;- return rightUpdated - leftUpdated;+ return byTier !== 0 ? byTier : comparePullRequestsByRecency(left, right);});}diff --git a/apps/web/src/components/pullRequest/pullRequestListGroups.logic.ts b/apps/web/src/components/pullRequest/pullRequestListGroups.logic.tsindex 0ea592ba008..9a3bda738a2 100644--- a/apps/web/src/components/pullRequest/pullRequestListGroups.logic.ts+++ b/apps/web/src/components/pullRequest/pullRequestListGroups.logic.ts@@ -7,6 +7,7 @@ import type {import type { PullRequestTabStatusSeed } from "~/components/RightPanelTabs";import { pullRequestSurfaceId } from "~/rightPanelStore";import {+ comparePullRequestsByRecency,filterPullRequestsByInvolvement,groupPullRequestsByInvolvement,matchesPullRequestFilters,@@ -65,9 +66,7 @@ export function pullRequestGroups({): involvementEntries;if (text.length === 0) {- return narrowedEntries.toSorted((left, right) =>- right.updatedAt.localeCompare(left.updatedAt),- );+ return narrowedEntries.toSorted(comparePullRequestsByRecency);}return narrowedEntries.filter((entry) =>