@devries-cameron20 / t3code-1 / commits / 2083a22919
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): PR Code tab no longer requests the diff of a commit the PR dropped (#25916)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 05:17 UTC 2083a22919549f7d0648de3c9c19f550c4d1ce93
2 files changed +46 -10
apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx
+40 -3
@@ -50,7 +50,7 @@ const { diffAtom, pagedDiffAtom } = await vi.hoisted(async () => {
50 };
51 });
52
53 -const mocks = vi.hoisted(() => ({ paged: false }));
53 +const mocks = vi.hoisted(() => ({ paged: false, diffCommits: [] as Array<string | undefined> }));
54
55 vi.mock(import("~/state/use-atom-command"), async (original) => ({
56 ...(await original()),
@@ -62,8 +62,10 @@ vi.mock(import("~/state/pullRequests"), async (original) => {
62 ...actual,
63 pullRequestEnvironment: {
64 ...actual.pullRequestEnvironment,
65 - diff: (({ input }: { input: { cursor?: string } }) =>
66 - mocks.paged ? pagedDiffAtom(input.cursor ?? "first") : diffAtom) as never,
65 + diff: (({ input }: { input: { cursor?: string; commit?: string } }) => {
66 + mocks.diffCommits.push(input.commit);
67 + return mocks.paged ? pagedDiffAtom(input.cursor ?? "first") : diffAtom;
68 + }) as never,
69 },
70 };
71 });
@@ -125,6 +127,7 @@ const detail: PullRequestDetailView = {
127
128 function setup({ paged }: { paged: boolean }) {
129 mocks.paged = paged;
130 + mocks.diffCommits = [];
131 }
132
133 const tab = (
@@ -199,3 +202,37 @@ it("pages forward to a file asked for that is not loaded yet, then scrolls to it
202
203 await expectFileHeaderShown(screen, container, "late.ts");
204 });
205 +
206 +it("never requests the diff of a selected commit the pull request no longer has", async () => {
207 + setup({ paged: false });
208 + const container = document.createElement("div");
209 + container.className = "flex h-[700px] w-[900px]";
210 + // The timeline can open a commit that a force-push removed from the pull request.
211 + await using screen = await render(
212 + <PullRequestCodeTab
213 + scrollerRef={() => {}}
214 + environmentId={EnvironmentId.make("environment")}
215 + reference={detail}
216 + detail={{
217 + ...detail,
218 + commits: [
219 + {
220 + oid: "kept",
221 + messageHeadline: "Kept commit",
222 + committedDate: "2026-09-01T00:00:00Z",
223 + },
224 + ],
225 + }}
226 + selectedCommitOid="gone"
227 + onSelectedCommitChange={() => {}}
228 + onRefresh={() => {}}
229 + />,
230 + { container },
231 + );
232 +
233 + await expect.element(screen.getByText("1 file", { exact: true })).toBeVisible();
234 + await expect
235 + .element(screen.getByRole("button", { name: "Diff scope: All commits" }))
236 + .toBeVisible();
237 + expect(mocks.diffCommits).not.toContain("gone");
238 +});
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+6 -7
@@ -314,7 +314,12 @@ function PullRequestCodeTab({
314 }>({ key: "", cursor: null, slices: NO_SLICES });
315
316 const referenceKey = pullRequestReviewKey(reference);
317 - const commit = selectedCommitOid;
317 + // A commit opened from the timeline or left selected across a force-push may no longer be
318 + // part of the pull request; read it as "All commits" instead of requesting its diff.
319 + const commit =
320 + selectedCommitOid !== null && detail.commits.some((entry) => entry.oid === selectedCommitOid)
321 + ? selectedCommitOid
322 + : null;
323 const scopeKey = JSON.stringify([environmentId, referenceKey, commit]);
324 // The panel keeps this mounted across pull requests, so an open composer would otherwise
325 // survive the switch and attach its comment to whichever one is on screen when it is sent.
@@ -983,7 +988,6 @@ function PullRequestCodeTab({
988 </div>
989 );
990
986 - // Clear obsolete commit scopes even when an empty list hides the dropdown.
991 const selectedCommit = orderedCommits.find((entry) => entry.oid === commit);
992 const scopeLabel = selectedCommit ? selectedCommit.messageHeadline : "All commits";
993 const changeIgnoreWhitespace = (next: boolean) => {
@@ -1297,11 +1301,6 @@ function PullRequestCodeTab({
1301 answerReveal();
1302 // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Re-checked as pages load until the requested file arrives.
1303 }, [canLoadNextSlice, items, revealRequest]);
1300 - useEffect(() => {
1301 - if (commit !== null && selectedCommit === undefined) {
1302 - onSelectedCommitChange(null);
1303 - }
1304 - }, [commit, onSelectedCommitChange, selectedCommit]);
1304 const withToolbar = (body: ReactNode) => (
1305 <div className="flex h-full min-h-0 flex-col">
1306 {toolbar}