GeezerVison is showing github.com — fix(web): PR Code tab no longer requests the diff of a commit the PR … · pingdotgg/t3code@2083a22
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/pullRequest
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx +40-3Lines changed: 40 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ const { diffAtom, pagedDiffAtom } = await vi.hoisted(async () => { | 50 | 50 | }; | 51 | 51 | }); | 52 | 52 |
| 53 | | -const mocks = vi.hoisted(() => ({ paged: false })); | | 53 | +const mocks = vi.hoisted(() => ({ paged: false, diffCommits: [] as Array<string | undefined> })); | 54 | 54 |
| 55 | 55 | vi.mock(import("~/state/use-atom-command"), async (original) => ({ | 56 | 56 | ...(await original()), | @@ -62,8 +62,10 @@ vi.mock(import("~/state/pullRequests"), async (original) => { | 62 | 62 | ...actual, | 63 | 63 | pullRequestEnvironment: { | 64 | 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, | 67 | 69 | }, | 68 | 70 | }; | 69 | 71 | }); | @@ -125,6 +127,7 @@ const detail: PullRequestDetailView = { | 125 | 127 |
| 126 | 128 | function setup({ paged }: { paged: boolean }) { | 127 | 129 | mocks.paged = paged; | | 130 | + mocks.diffCommits = []; | 128 | 131 | } | 129 | 132 |
| 130 | 133 | const tab = ( | @@ -199,3 +202,37 @@ it("pages forward to a file asked for that is not loaded yet, then scrolls to it | 199 | 202 |
| 200 | 203 | await expectFileHeaderShown(screen, container, "late.ts"); | 201 | 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 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestCodeTab.tsx +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -314,7 +314,12 @@ function PullRequestCodeTab({ | 314 | 314 | }>({ key: "", cursor: null, slices: NO_SLICES }); | 315 | 315 |
| 316 | 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; | 318 | 323 | const scopeKey = JSON.stringify([environmentId, referenceKey, commit]); | 319 | 324 | // The panel keeps this mounted across pull requests, so an open composer would otherwise | 320 | 325 | // survive the switch and attach its comment to whichever one is on screen when it is sent. | @@ -983,7 +988,6 @@ function PullRequestCodeTab({ | 983 | 988 | </div> | 984 | 989 | ); | 985 | 990 |
| 986 | | - // Clear obsolete commit scopes even when an empty list hides the dropdown. | 987 | 991 | const selectedCommit = orderedCommits.find((entry) => entry.oid === commit); | 988 | 992 | const scopeLabel = selectedCommit ? selectedCommit.messageHeadline : "All commits"; | 989 | 993 | const changeIgnoreWhitespace = (next: boolean) => { | @@ -1297,11 +1301,6 @@ function PullRequestCodeTab({ | 1297 | 1301 | answerReveal(); | 1298 | 1302 | // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Re-checked as pages load until the requested file arrives. | 1299 | 1303 | }, [canLoadNextSlice, items, revealRequest]); | 1300 | | - useEffect(() => { | 1301 | | - if (commit !== null && selectedCommit === undefined) { | 1302 | | - onSelectedCommitChange(null); | 1303 | | - } | 1304 | | - }, [commit, onSelectedCommitChange, selectedCommit]); | 1305 | 1304 | const withToolbar = (body: ReactNode) => ( | 1306 | 1305 | <div className="flex h-full min-h-0 flex-col"> | 1307 | 1306 | {toolbar} | |
|