Skip to content
TypeScript

fix(web): reuse pull request list data while loading (#9467)

maria493fbb58870c
diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
index 59aa1333896..c94e4bf3810 100644
--- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
@@ -4,6 +4,7 @@ import {
type EnvironmentId,
type PullRequestAction,
type PullRequestMergeMethod,
+ type PullRequestListEntry,
type PullRequestUpdateMethod,
type PullRequestRef,
type PullRequestState,
@@ -447,6 +448,7 @@ export function PullRequestDetailPanel({
environmentId,
threadRef = null,
reference,
+ listEntry = null,
refreshToken: forcedRefreshToken = 0,
onActed,
onClose,
@@ -463,6 +465,8 @@ export function PullRequestDetailPanel({
*/
threadRef?: ScopedThreadRef | null;
reference: PullRequestRef;
+ /** Row fields already loaded by the pull-request list, used while richer detail arrives. */
+ listEntry?: PullRequestListEntry | null;
/**
* Bumped by whatever holds the panel when a reader asks for everything on screen to be read
* again. The panel owns its own reads, so the page cannot refresh them for it — it says when,
@@ -491,6 +495,12 @@ export function PullRequestDetailPanel({
composerDraftTarget?: ScopedThreadRef | DraftId;
}) {
const pullRequestKey = `${reference.projectId}:${reference.repository}#${reference.number}`;
+ const matchingListEntry =
+ listEntry?.projectId === reference.projectId &&
+ listEntry.repository.toLowerCase() === reference.repository.toLowerCase() &&
+ listEntry.number === reference.number
+ ? listEntry
+ : null;
const [tab, setTab] = useState<DetailTab>("summary");
const [timelineOrder, setTimelineOrder] = useState<"newest" | "oldest">("newest");
const [codeCommitScope, setCodeCommitScope] = useState<{
@@ -1296,10 +1306,10 @@ export function PullRequestDetailPanel({
).length
: 0;
- // A reopen already has last time's title, author, and counts. Keep them on screen
- // and let the live read replace fields — especially the diff counts — in place.
+ // The list already has the pull request's identity and summary. Keep them on screen
+ // and let the richer detail read replace the remaining placeholders in place.
if (detailQuery.isPending && !detail) {
- return <PullRequestDetailGhost />;
+ return <PullRequestDetailGhost seed={matchingListEntry} />;
}
return (
diff --git a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
index 2ae79c063c3..f8c92235654 100644
--- a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
+++ b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx
@@ -7,7 +7,19 @@
* both themes) and the single `animate-skeleton` pulse, applied once on the container so any
* number of bars costs one opacity animation.
*/
+import type { PullRequestListEntry } from "@t3tools/contracts";
+import { ArrowLeftIcon } from "lucide-react";
+
import { cn } from "~/lib/utils";
+import { formatRelativeTimeLabel } from "~/timestampFormat";
+
+import { pullRequestLabelColor } from "./pullRequestList.logic";
+import {
+ PullRequestActorLabel,
+ PullRequestDiffStat,
+ pullRequestChecksStatePresentation,
+ resolvePullRequestState,
+} from "./pullRequestPresentation";
function GhostBar({ className }: { className?: string | undefined }) {
return <div aria-hidden className={cn("h-3 rounded bg-muted-foreground/15", className)} />;
@@ -60,18 +72,46 @@ export function PullRequestListGhost({
* boundaries in the ghost prevents the loaded pull request from replacing one layout with
* another a moment later.
*/
-export function PullRequestDetailGhost() {
+export function PullRequestDetailGhost({ seed }: { seed?: PullRequestListEntry | null }) {
+ const statePresentation = seed
+ ? resolvePullRequestState({
+ state: seed.state,
+ isDraft: seed.isDraft,
+ })
+ : null;
+ const checksPresentation = seed?.checksState
+ ? pullRequestChecksStatePresentation(seed.checksState)
+ : null;
+
return (
<div
role="status"
aria-label="Loading pull request"
- className="motion-safe:animate-skeleton flex h-full min-h-0 flex-col overflow-hidden bg-background"
+ className={cn(
+ "flex h-full min-h-0 flex-col overflow-hidden bg-background",
+ !seed && "motion-safe:animate-skeleton",
+ )}
>
<div className="shrink-0 border-b border-border/60">
<div className="flex h-7 items-center justify-between gap-3 px-4">
<div className="flex min-w-0 flex-1 items-center gap-1.5">
- <GhostBar className="w-24" />
- <GhostBar className="w-9" />
+ {seed && statePresentation ? (
+ <>
+ <span className="min-w-0 truncate text-xs font-medium text-muted-foreground">
+ {seed.repository}
+ </span>
+ <span
+ className={cn("shrink-0 text-xs font-medium", statePresentation.toneClassName)}
+ >
+ #{seed.number}
+ </span>
+ </>
+ ) : (
+ <>
+ <GhostBar className="w-24" />
+ <GhostBar className="w-9" />
+ </>
+ )}
</div>
<div className="flex shrink-0 items-center gap-1">
<GhostBar className="h-5 w-16 rounded-md" />
@@ -80,18 +120,58 @@ export function PullRequestDetailGhost() {
</div>
<div className="px-4 pb-4 pt-1">
- <GhostBar className="h-5 w-4/5 max-w-md" />
+ {seed ? (
+ <h1 className="truncate text-base font-semibold leading-snug">{seed.title}</h1>
+ ) : (
+ <GhostBar className="h-5 w-4/5 max-w-md" />
+ )}
<div className="mt-2 flex items-center gap-1.5">
- <GhostBar className="size-4 rounded-full" />
- <GhostBar className="w-24" />
+ {seed ? (
+ <>
+ <PullRequestActorLabel
+ actor={seed.author}
+ className="font-medium"
+ tooltip={false}
+ />
+ <span className="text-xs text-muted-foreground">
+ updated {formatRelativeTimeLabel(seed.updatedAt)}
+ </span>
+ </>
+ ) : (
+ <>
+ <GhostBar className="size-4 rounded-full" />
+ <GhostBar className="w-24" />
+ </>
+ )}
</div>
<div className="mt-4 flex min-w-0 items-center gap-2">
- <GhostBar className="h-6 w-24 rounded-md" />
- <GhostBar className="size-3 rounded-full" />
- <GhostBar className="h-6 w-32 rounded-md" />
+ {seed ? (
+ <span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
+ <code className="min-w-0 max-w-[40%] shrink-0 truncate">{seed.baseBranch}</code>
+ <ArrowLeftIcon
+ aria-label="receives changes from"
+ className="size-3.5 shrink-0 opacity-60"
+ />
+ <code className="min-w-0 flex-1 truncate">{seed.headBranch}</code>
+ </span>
+ ) : (
+ <>
+ <GhostBar className="h-6 w-24 rounded-md" />
+ <GhostBar className="size-3 rounded-full" />
+ <GhostBar className="h-6 w-32 rounded-md" />
+ </>
+ )}
<div className="ml-auto flex shrink-0 items-center gap-2">
<GhostBar className="w-10" />
- <GhostBar className="w-20" />
+ {seed ? (
+ <PullRequestDiffStat
+ additions={seed.additions}
+ deletions={seed.deletions}
+ className="font-mono text-xs"
+ />
+ ) : (
+ <GhostBar className="w-20" />
+ )}
</div>
</div>
</div>
@@ -102,7 +182,19 @@ export function PullRequestDetailGhost() {
<GhostBar className="h-6 w-16 rounded-md" />
<GhostBar className="h-6 w-12 rounded-md" />
</div>
- <GhostBar className="w-20" />
+ {checksPresentation ? (
+ <span
+ className={cn(
+ "inline-flex items-center gap-1.5 text-xs",
+ checksPresentation.toneClassName,
+ )}
+ >
+ <checksPresentation.Icon aria-hidden className="size-3.5" />
+ {checksPresentation.label}
+ </span>
+ ) : (
+ <GhostBar className="w-20" />
+ )}
</div>
</div>
@@ -125,8 +217,29 @@ export function PullRequestDetailGhost() {
<GhostBar className="w-10" />
</div>
<div className="flex items-center gap-1">
- <GhostBar className="h-5 w-24 rounded-full" />
- <GhostBar className="h-5 w-20 rounded-full" />
+ {seed ? (
+ seed.labels.slice(0, 3).map((label) => {
+ const color = pullRequestLabelColor(label.color);
+ return (
+ <span
+ key={label.name}
+ className="inline-flex h-5 max-w-32 items-center gap-1 truncate rounded-full border border-border/70 bg-muted/40 px-2 text-[10px] text-muted-foreground"
+ >
+ <span
+ aria-hidden
+ className="size-2 shrink-0 rounded-full bg-muted-foreground"
+ {...(color ? { style: { backgroundColor: color } } : {})}
+ />
+ <span className="truncate">{label.name}</span>
+ </span>
+ );
+ })
+ ) : (
+ <>
+ <GhostBar className="h-5 w-24 rounded-full" />
+ <GhostBar className="h-5 w-20 rounded-full" />
+ </>
+ )}
</div>
</div>
<div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx
index 29e6b05c0b1..6db4f99b150 100644
--- a/apps/web/src/routes/_chat.pull-requests.tsx
+++ b/apps/web/src/routes/_chat.pull-requests.tsx
@@ -220,6 +220,9 @@ const EMPTY_TERMINAL_LABELS = new Map<string, string>();
const EMPTY_PENDING_SURFACES = new Set<string>();
const MAX_SEARCH_LABEL_CANDIDATES = 100;
+const pullRequestListEntryId = (target: Parameters<typeof pullRequestSurfaceId>[0]) =>
+ pullRequestSurfaceId({ ...target, repository: target.repository.toLowerCase() });
+
function pullRequestSearchLabels(raw: unknown): Partial<Pick<PullRequestsSearch, "labels">> {
const values = (Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : []).slice(
0,
@@ -1436,6 +1439,15 @@ function PullRequestsRouteView() {
entry.additions + entry.deletions > 0 || statsByRow.has(pullRequestDiffStatKey(entry)),
);
}, [groups, sort, statsByRow, typedParsed.text]);
+ const listedPullRequestsBySurface = useMemo(
+ () =>
+ new Map(
+ displayGroups.flatMap((group) =>
+ group.entries.map((entry) => [pullRequestListEntryId(entry), entry] as const),
+ ),
+ ),
+ [displayGroups],
+ );
const linkedSelection = useMemo(
() =>
@@ -1939,6 +1951,11 @@ function PullRequestsRouteView() {
repository: renderedPullRequestSurface.repository,
number: renderedPullRequestSurface.number,
}}
+ listEntry={
+ listedPullRequestsBySurface.get(
+ pullRequestListEntryId(renderedPullRequestSurface),
+ ) ?? null
+ }
refreshToken={detailRefreshToken}
// Merging, closing or reopening changes the row this panel was opened from, so
// the list behind it is out of date the moment the host takes the action.