Skip to content

Commit dabb4b6

Browse files
committed
fix(web): preserve cached PR identity for legacy servers
1 parent 332836d commit dabb4b6

5 files changed

Lines changed: 114 additions & 33 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.test.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type ScopedThreadRef,
66
type PullRequestDetailView,
77
type PullRequestSummary,
8+
type PullRequestListEntry,
89
type ThreadPullRequestLink,
910
} from "@t3tools/contracts";
1011
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
@@ -343,10 +344,11 @@ describe.each([
343344
});
344345

345346
describe("PR list status in the sidebar detail", () => {
346-
const panel = () => (
347+
const panel = (listEntry: PullRequestListEntry | null = null) => (
347348
<PullRequestDetailPanel
348349
environmentId={threadRef.environmentId}
349350
reference={detail}
351+
listEntry={listEntry}
350352
shortcutsEnabled={false}
351353
getShortcutContext={() => ({
352354
terminalFocus: false,
@@ -372,6 +374,18 @@ describe("PR list status in the sidebar detail", () => {
372374
expect(renderer.root.findAllByType("button")).toHaveLength(0);
373375
});
374376

377+
it("keeps the list conflict when the shared summary omits mergeability", async () => {
378+
loadedDetail = null;
379+
observedSummary = { ...detail, mergeability: undefined, isDraft: undefined };
380+
const row = { ...detail, host: "github.com", viewerReviewRequested: false };
381+
await act(async () => {
382+
renderer = create(panel(row));
383+
});
384+
expect(
385+
renderer.root.findAll((node) => node.children.includes("Conflicts with main")),
386+
).toHaveLength(1);
387+
});
388+
375389
it("uses the list conflict while an older detail snapshot is displayed", async () => {
376390
loadedDetail = { ...detail, mergeability: "mergeable" };
377391
await act(async () => {

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ import {
149149
PULL_REQUEST_MERGE_METHOD_LABELS,
150150
readableFailure,
151151
readPullRequestDetailSnapshot,
152-
resolvePullRequestReferenceHost,
153152
resolveDisplayedPullRequestDetail,
153+
resolvePullRequestPanelReferences,
154154
resolvePullRequestPrimaryControl,
155155
allowsSinglePullRequestMerge,
156156
resolveBaseFreshness,
@@ -532,24 +532,22 @@ export function PullRequestDetailPanel({
532532
)?.repositoryIdentity;
533533
const supportsThreadPullRequests =
534534
environmentConfigs.get(environmentId)?.environment.capabilities.threadPullRequests === true;
535-
const reference = useMemo(
535+
const { reference, cacheReference } = useMemo(
536536
() =>
537-
supportsThreadPullRequests
538-
? resolvePullRequestReferenceHost(requestedReference, repositoryIdentity)
539-
: {
540-
projectId: requestedReference.projectId,
541-
repository: requestedReference.repository,
542-
number: requestedReference.number,
543-
},
537+
resolvePullRequestPanelReferences(
538+
requestedReference,
539+
repositoryIdentity,
540+
supportsThreadPullRequests,
541+
),
544542
[requestedReference, repositoryIdentity, supportsThreadPullRequests],
545543
);
546-
const pullRequestKey = `${reference.projectId}:${reference.host ?? ""}:${reference.repository}#${reference.number}`;
544+
const pullRequestKey = `${cacheReference.projectId}:${cacheReference.host ?? ""}:${cacheReference.repository}#${cacheReference.number}`;
547545
const matchingListEntry =
548-
listEntry?.projectId === reference.projectId &&
549-
listEntry.repository.toLowerCase() === reference.repository.toLowerCase() &&
550-
(reference.host === undefined ||
551-
listEntry.host.toLowerCase() === reference.host.toLowerCase()) &&
552-
listEntry.number === reference.number
546+
listEntry?.projectId === cacheReference.projectId &&
547+
listEntry.repository.toLowerCase() === cacheReference.repository.toLowerCase() &&
548+
(cacheReference.host === undefined ||
549+
listEntry.host.toLowerCase() === cacheReference.host.toLowerCase()) &&
550+
listEntry.number === cacheReference.number
553551
? listEntry
554552
: null;
555553
const [threadPickerOpen, setThreadPickerOpen] = useState(false);
@@ -648,47 +646,53 @@ export function PullRequestDetailPanel({
648646
readPullRequestDetailSnapshot(
649647
typeof window === "undefined" ? undefined : window.localStorage,
650648
environmentId,
651-
reference,
649+
cacheReference,
652650
),
653651
);
654652
useEffect(() => {
655653
setCachedDetail(
656654
readPullRequestDetailSnapshot(
657655
typeof window === "undefined" ? undefined : window.localStorage,
658656
environmentId,
659-
reference,
657+
cacheReference,
660658
),
661659
);
662-
}, [environmentId, pullRequestKey, reference.projectId, reference.repository, reference.number]);
660+
}, [
661+
environmentId,
662+
pullRequestKey,
663+
cacheReference.projectId,
664+
cacheReference.repository,
665+
cacheReference.number,
666+
]);
663667
useEffect(() => {
664668
if (detailQuery.data === null) return;
665669
writePullRequestDetailSnapshot(
666670
typeof window === "undefined" ? undefined : window.localStorage,
667671
environmentId,
668-
reference,
672+
cacheReference,
669673
detailQuery.data,
670674
);
671675
setCachedDetail(detailQuery.data);
672676
}, [
673677
detailQuery.data,
674678
environmentId,
675679
pullRequestKey,
676-
reference.projectId,
677-
reference.repository,
678-
reference.number,
680+
cacheReference.projectId,
681+
cacheReference.repository,
682+
cacheReference.number,
679683
]);
680684
const resolvedCoreDetail = resolveDisplayedPullRequestDetail({
681685
live: detailQuery.data,
682686
cached: cachedDetail,
683-
reference,
687+
reference: cacheReference,
684688
});
685689
const listSummary = useMemo(
686690
() => (matchingListEntry === null ? null : pullRequestListEntryToSummary(matchingListEntry)),
687691
[matchingListEntry],
688692
);
689693
const observedSummary = useSharedPullRequestSummary(
690694
environmentId,
691-
reference,
695+
cacheReference,
692696
detailQuery.data,
693697
detailQuery.dataUpdatedAt,
694698
);

‎apps/web/src/components/pullRequest/PullRequestGhosts.tsx‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ export function PullRequestDetailGhost({
8080
seed?: PullRequestListEntry | null;
8181
summary?: PullRequestSummary | null;
8282
}) {
83-
const seed = summary ? { ...entry, ...summary } : entry;
83+
const seed = summary
84+
? {
85+
...entry,
86+
...summary,
87+
isDraft: summary.isDraft ?? entry?.isDraft,
88+
mergeability: summary.mergeability ?? entry?.mergeability,
89+
}
90+
: entry;
8491
const statePresentation = seed
8592
? resolvePullRequestState({
8693
state: seed.state,
@@ -90,13 +97,12 @@ export function PullRequestDetailGhost({
9097
const checksPresentation = seed?.checksState
9198
? pullRequestChecksStatePresentation(seed.checksState)
9299
: null;
93-
const conflictSource = summary ?? seed;
94-
const conflictPresentation = conflictSource
100+
const conflictPresentation = seed
95101
? resolvePullRequestConflict({
96-
state: conflictSource.state,
97-
isDraft: conflictSource.isDraft ?? false,
98-
mergeability: conflictSource.mergeability ?? "unknown",
99-
baseBranch: conflictSource.baseBranch,
102+
state: seed.state,
103+
isDraft: seed.isDraft ?? false,
104+
mergeability: seed.mergeability ?? "unknown",
105+
baseBranch: seed.baseBranch,
100106
})
101107
: null;
102108

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,27 @@ export function resolvePullRequestReferenceHost(
11291129
return { ...reference, host: pullRequestHostOf(identity, "github") };
11301130
}
11311131

1132+
export function resolvePullRequestPanelReferences(
1133+
requestedReference: PullRequestRef,
1134+
identity: RepositoryIdentity | null | undefined,
1135+
supportsThreadPullRequests: boolean,
1136+
): { readonly reference: PullRequestRef; readonly cacheReference: PullRequestRef } {
1137+
const resolvedReference = resolvePullRequestReferenceHost(requestedReference, identity);
1138+
if (supportsThreadPullRequests) {
1139+
return { reference: resolvedReference, cacheReference: resolvedReference };
1140+
}
1141+
return {
1142+
reference: {
1143+
projectId: requestedReference.projectId,
1144+
repository: requestedReference.repository,
1145+
number: requestedReference.number,
1146+
},
1147+
// Legacy servers cannot receive a host, but the client cache must retain it so rows from
1148+
// github.com and a GitHub Enterprise host cannot share a summary.
1149+
cacheReference: resolvedReference,
1150+
};
1151+
}
1152+
11321153
export interface PullRequestDetailSnapshotRef {
11331154
readonly host?: string | undefined;
11341155
readonly projectId: string;

‎apps/web/src/state/pullRequests.test.tsx‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
type PullRequestListEntry,
55
type PullRequestListInput,
66
type PullRequestListResult,
7+
type PullRequestRef,
78
type PullRequestSummary,
89
} from "@t3tools/contracts";
910
import { AsyncResult, Atom } from "effect/unstable/reactivity";
1011
import { act, useLayoutEffect } from "react";
1112
import { create, type ReactTestRenderer } from "react-test-renderer";
1213
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
1314

15+
import { resolvePullRequestPanelReferences } from "../components/pullRequest/pullRequestDetail.logic";
16+
1417
import { appAtomRegistry, AppAtomRegistryProvider } from "../rpc/atomRegistry";
1518
import {
1619
pullRequestEnvironment,
@@ -124,7 +127,7 @@ function SidebarProbe({
124127
observedAt,
125128
}: {
126129
environmentId: EnvironmentId;
127-
reference: ReturnType<typeof reference>;
130+
reference: PullRequestRef;
128131
current?: PullRequestSummary | null;
129132
observedAt?: number | null;
130133
}) {
@@ -171,6 +174,39 @@ describe("pull request summary cache", () => {
171174
expect(observed?.mergeability).toBe("conflicting");
172175
});
173176

177+
it("reuses host-scoped list summaries when a legacy server needs hostless requests", async () => {
178+
const environmentId = EnvironmentId.make(`cache-${sequence++}`);
179+
const publicRow = entry({ title: "Public PR" });
180+
const enterpriseRow = entry({
181+
host: "github.example.test",
182+
url: "https://github.example.test/acme/widget/pull/7",
183+
title: "Enterprise PR",
184+
mergeability: "conflicting",
185+
});
186+
appAtomRegistry.set(
187+
listAtomFor(environmentId),
188+
AsyncResult.success(answer(publicRow, enterpriseRow), { timestamp: 200 }),
189+
);
190+
await mount(<ListProbe environmentIds={[environmentId]} />);
191+
192+
const legacy = resolvePullRequestPanelReferences(reference(enterpriseRow), null, false);
193+
expect(legacy.reference).toEqual({
194+
projectId,
195+
repository: enterpriseRow.repository,
196+
number: enterpriseRow.number,
197+
});
198+
await mount(<SidebarProbe environmentId={environmentId} reference={legacy.cacheReference} />);
199+
expect(observed?.title).toBe("Enterprise PR");
200+
expect(observed?.mergeability).toBe("conflicting");
201+
202+
const publicLegacy = resolvePullRequestPanelReferences(reference(publicRow), null, false);
203+
await mount(
204+
<SidebarProbe environmentId={environmentId} reference={publicLegacy.cacheReference} />,
205+
);
206+
expect(observed?.title).toBe("Public PR");
207+
expect(observed?.mergeability).toBe("mergeable");
208+
});
209+
174210
it("keeps environments and hosts isolated, then accepts a newer same-dated update", async () => {
175211
const firstEnvironment = EnvironmentId.make(`cache-${sequence++}`);
176212
const secondEnvironment = EnvironmentId.make(`cache-${sequence++}`);

0 commit comments

Comments
 (0)