The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 17:15 UTC
fix(web): PR Code tab previews images the host sends no patch for (#36056)
Julius Marminge committed
Nov 12, 2026 at 23:33 UTC
b80531d6fbcb8e3451595c2ccd0900a5b6fc7792
5 files changed
+89
-3
apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
+47
-2
@@ -7,7 +7,12 @@ import {
7
capitalizeTerm,
8
sourceControlClients,
9
} from "@t3tools/client-runtime/source-control-clients";
10
-import type { CodeViewItem, DiffLineAnnotation, SelectedLineRange } from "@pierre/diffs";
10
+import type {
11
+ CodeViewItem,
12
+ DiffLineAnnotation,
13
+ FileDiffMetadata,
14
+ SelectedLineRange,
15
+} from "@pierre/diffs";
16
import type { CodeViewAnnotationArgs, CodeViewDiffItem } from "@pierre/diffs/react";
17
import type {
18
EnvironmentId,
@@ -20,6 +25,7 @@ import type {
25
PullRequestReviewThread,
26
PullRequestThreadCommentsResult,
27
} from "@t3tools/contracts";
28
+import { SOURCE_CONTROL_MEDIA_ASSET } from "@t3tools/contracts";
29
import {
30
ChevronDownIcon,
31
ChevronRightIcon,
@@ -64,6 +70,7 @@ import {
70
} from "@t3tools/client-runtime/pull-request-editing";
71
import { fileDiffRows } from "@t3tools/client-runtime/review-guide-tour";
72
import { isTestChangedFile } from "@t3tools/shared/changedFileKind";
73
+import { isWorkspaceImagePreviewPath } from "@t3tools/shared/mediaPreview";
74
import { orderDiffFiles } from "./pullRequestFileOrder.logic";
75
import {
76
buildFileDiffRenderKey,
@@ -88,6 +95,7 @@ import { pullRequestEnvironment } from "~/state/pullRequests";
95
import { useEnvironmentQuery } from "~/state/query";
96
import { useAtomCommand } from "~/state/use-atom-command";
97
98
+import { ChatMarkdownAssetImage } from "../chat/ChatMarkdownMedia";
99
import { DiffPanelLoadingState } from "../DiffPanelShell";
100
import { useDiffWorkerPool } from "../DiffWorkerPoolProvider";
101
import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation";
@@ -144,6 +152,7 @@ interface ReviewAnnotationGroup {
152
readonly threads: ReadonlyArray<PullRequestReviewThread>;
153
readonly pending: ReadonlyArray<PendingReviewComment>;
154
readonly draft: boolean;
155
+ readonly image?: { readonly url: string; readonly path: string };
156
}
157
158
type ReviewAnnotation = DiffLineAnnotation<ReviewAnnotationGroup>;
@@ -637,6 +646,20 @@ function PullRequestCodeTab({
646
return placed;
647
})();
648
649
+ const imageRevision = commit ?? detail.headSha;
650
+ const rawFileUrl = sourceControlClients.find(detail.provider)?.rawFileUrl;
651
+ const repositoryUrl = sourceControlClients.parseChangeRequestUrl(detail.url)?.link.repositoryUrl;
652
+ // Hosts send no patch for an image, so its expanded row shows the file at this revision.
653
+ const imagePreviewUrl = (fileDiff: FileDiffMetadata, path: string) =>
654
+ fileDiff.hunks.length === 0 &&
655
+ fileDiff.type !== "deleted" &&
656
+ isWorkspaceImagePreviewPath(path) &&
657
+ imageRevision !== undefined &&
658
+ rawFileUrl !== undefined &&
659
+ repositoryUrl !== undefined
660
+ ? rawFileUrl({ repositoryUrl, sha: imageRevision, path })
661
+ : null;
662
+
663
const annotatedFiles = files.map((fileDiff) => {
664
const fileKey = buildFileDiffRenderKey(fileDiff);
665
const path = resolveFileDiffPath(fileDiff);
@@ -689,6 +712,14 @@ function PullRequestCodeTab({
712
lineNumber: group.line,
713
metadata: { threads: group.threads, pending: group.pending, draft: group.draft },
714
}));
715
+ const imageUrl = imagePreviewUrl(fileDiff, path);
716
+ if (imageUrl !== null) {
717
+ annotations.push({
718
+ side: "additions",
719
+ lineNumber: 0,
720
+ metadata: { threads: [], pending: [], draft: false, image: { url: imageUrl, path } },
721
+ });
722
+ }
723
return {
724
fileKey,
725
path,
@@ -699,7 +730,7 @@ function PullRequestCodeTab({
730
annotations
731
.map(
732
({ side, lineNumber, metadata }) =>
702
- `${side}:${lineNumber}:${metadata.draft ? "d" : ""}:${metadata.pending
733
+ `${side}:${lineNumber}:${metadata.image?.url ?? ""}:${metadata.draft ? "d" : ""}:${metadata.pending
734
.map((comment) => `${comment.id}:${comment.body}`)
735
.join(",")}:${metadata.threads
736
.map(
@@ -1085,6 +1116,20 @@ function PullRequestCodeTab({
1116
const renderAnnotation = (...[annotation]: CodeViewAnnotationArgs<ReviewAnnotationGroup>) => (
1117
// Folded resolved conversations alone add no row, so the code reads straight through.
1118
<div className="relative font-sans text-foreground has-[>:not([data-resolved-threads])]:py-1">
1119
+ {annotation.metadata.image ? (
1120
+ <div className="flex justify-center p-3">
1121
+ <ChatMarkdownAssetImage
1122
+ environmentId={environmentId}
1123
+ resource={{
1124
+ _tag: SOURCE_CONTROL_MEDIA_ASSET,
1125
+ cwd: detail.workspaceRoot,
1126
+ url: annotation.metadata.image.url,
1127
+ repository: detail.repository,
1128
+ }}
1129
+ alt={annotation.metadata.image.path}
1130
+ />
1131
+ </div>
1132
+ ) : null}
1133
<InlineReviewThreads threads={annotation.metadata.threads} renderThread={renderThreadCard} />
1134
{annotation.metadata.pending.map((comment) => (
1135
<PendingReviewCommentCard
packages/source-control-core/src/shared/definition.ts
+9
@@ -354,6 +354,15 @@ export interface SourceControlDefinition {
354
* media itself, so it asks the server, whose driver for this host fetches it.
355
*/
356
readonly mediaUrl?: (url: URL) => SourceControlMediaUrl | null;
357
+ /**
358
+ * A URL `mediaUrl` claims for the bytes of `path` at full commit `sha` in the repository at
359
+ * `repositoryUrl`. Null or absent when the host cannot serve one.
360
+ */
361
+ readonly rawFileUrl?: (input: {
362
+ readonly repositoryUrl: string;
363
+ readonly sha: string;
364
+ readonly path: string;
365
+ }) => string | null;
366
readonly settings?: SourceControlHostSettingsSchema;
367
}
368
packages/source-control-github/src/shared/definition.test.ts
+15
@@ -194,4 +194,19 @@ describe("GitHub media URLs", () => {
194
expect(media(url), url).toBeNull();
195
}
196
});
197
+
198
+ it("addresses a committed file at a full SHA as immutable credentialed media", () => {
199
+ const sha = "0123456789abcdef0123456789abcdef01234567";
200
+ const rawFileUrl = (repositoryUrl: string, path: string, revision = sha) =>
201
+ definition.rawFileUrl?.({ repositoryUrl, sha: revision, path }) ?? null;
202
+ const url = rawFileUrl("https://github.com/owner/repo", "docs/a #1?.png");
203
+ expect(url).toBe(`https://github.com/owner/repo/raw/${sha}/docs/a%20%231%3F.png`);
204
+ expect(media(url ?? "")).toEqual({
205
+ fetchUrl: `https://raw.githubusercontent.com/owner/repo/${sha}/docs/a%20%231%3F.png`,
206
+ fileName: "a #1?.png",
207
+ immutable: true,
208
+ });
209
+ expect(rawFileUrl("https://github.com/owner/repo", "a.png", "main")).toBeNull();
210
+ expect(rawFileUrl("https://github.example.com/owner/repo", "a.png")).toBeNull();
211
+ });
212
});
packages/source-control-github/src/shared/definition.ts
+2
-1
@@ -14,7 +14,7 @@ import {
14
type SourceControlAppSignIn,
15
} from "@t3tools/source-control-core/shared/definition";
16
17
-import { gitHubMediaUrl } from "./gitHubMedia.ts";
17
+import { gitHubMediaUrl, gitHubRawFileUrl } from "./gitHubMedia.ts";
18
import { icon } from "./icon.ts";
19
import { gitHubReferenceAutolinks } from "./referenceAutolinks.ts";
20
@@ -157,5 +157,6 @@ export const definition = defineSourceControl({
157
canReadChangeRequestOnHost: (identity, link) =>
158
isChangeRequestOnProjectHost(projectChangeRequestHost(identity, KIND), identity, link),
159
mediaUrl: gitHubMediaUrl,
160
+ rawFileUrl: gitHubRawFileUrl,
161
settings,
162
});
packages/source-control-github/src/shared/gitHubMedia.ts
+16
@@ -64,3 +64,19 @@ export function gitHubMediaUrl(url: URL): SourceControlMediaUrl | null {
64
? rawFile(`https://${RAW_HOST}/${repositoryFile[1]}/${repositoryFile[2]}/${repositoryFile[3]}`)
65
: null;
66
}
67
+
68
+export function gitHubRawFileUrl(input: {
69
+ readonly repositoryUrl: string;
70
+ readonly sha: string;
71
+ readonly path: string;
72
+}): string | null {
73
+ if (!COMMIT_SHA_PATTERN.test(input.sha)) return null;
74
+ const path = input.path.split("/").map(encodeURIComponent).join("/");
75
+ let url: URL;
76
+ try {
77
+ url = new URL(`${input.repositoryUrl}/raw/${input.sha}/${path}`);
78
+ } catch {
79
+ return null;
80
+ }
81
+ return gitHubMediaUrl(url) === null ? null : url.toString();
82
+}