@devries-cameron20 / t3code-1 / commits / d929e726f2
Fork 0

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

fix(pr): GitCafe attachments render in pull request bodies (#31741)

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

Julius Marminge committed Nov 5, 2026 at 16:50 UTC d929e726f223a3b76838ebbd839cce59e1ab0abe
5 files changed +74 -16
apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx
+16 -4
@@ -11,7 +11,10 @@ import {
11 } from "./PullRequestMedia";
12 import { videoMimeType } from "@t3tools/shared/video";
13 import { createContext, useContext, useMemo, useState } from "react";
14 -import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
14 +import {
15 + changeRequestReferenceAutolinker,
16 + resolveChangeRequestMediaUrl,
17 +} from "@t3tools/client-runtime/pull-request-markdown";
18 import {
19 sourceControlClients,
20 type ReferenceAutolink,
@@ -37,6 +40,7 @@ const AutolinksContext = createContext<((text: string) => ReadonlyArray<Referenc
40 null,
41 );
42 const LineBreaksContext = createContext(false);
43 +const ChangeRequestUrlContext = createContext<string | null>(null);
44
45 export function PullRequestMarkdownRepository(props: {
46 /** The change request the markdown belongs to, whose host decides what its text links. */
@@ -63,7 +67,9 @@ export function PullRequestMarkdownRepository(props: {
67 return (
68 <AutolinksContext value={autolinks}>
69 <LineBreaksContext value={lineBreaks}>
66 - <PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
70 + <ChangeRequestUrlContext value={url ?? null}>
71 + <PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
72 + </ChangeRequestUrlContext>
73 </LineBreaksContext>
74 </AutolinksContext>
75 );
@@ -159,6 +165,9 @@ function PullRequestMarkdownContent(props: {
165 const hostLineBreaks = useContext(LineBreaksContext);
166 const autolinks = useContext(AutolinksContext);
167 const mediaContext = useContext(PullRequestMediaContext);
168 + const changeRequestUrl = useContext(ChangeRequestUrlContext);
169 + const resolveMediaUrl = (href: string) =>
170 + changeRequestUrl ? resolveChangeRequestMediaUrl(href, changeRequestUrl) : href;
171 const markdown = linkReferenceAutolinks(props.markdown, autolinks);
172 const openPullRequest = useOpenPullRequest();
173 const openLink = (href: string) => {
@@ -167,6 +176,7 @@ function PullRequestMarkdownContent(props: {
176 const gallery: FilePreviewItem[] = markdownImageSources(
177 props.imageGroupMarkdown ?? props.markdown,
178 )
179 + .map(resolveMediaUrl)
180 .filter(
181 (uri) =>
182 /^https?:\/\//i.test(uri) &&
@@ -175,7 +185,7 @@ function PullRequestMarkdownContent(props: {
185 .map((uri) => pullRequestImageSource(uri, mediaContext));
186 const [preview, setPreview] = useState<FilePreviewSource | null>(null);
187 const renderImage: MarkdownImageRenderer = (image) => (
178 - <MarkdownImage href={image.href} alt={image.alt} onPreview={setPreview} />
188 + <MarkdownImage href={resolveMediaUrl(image.href)} alt={image.alt} onPreview={setPreview} />
189 );
190 const styles = useMarkdownPreviewStyles();
191 return (
@@ -186,7 +196,9 @@ function PullRequestMarkdownContent(props: {
196 textStyle={styles.nativeTextStyle}
197 onLinkPress={openLink}
198 renderImage={renderImage}
189 - onImagePress={(href) => setPreview(pullRequestImageSource(href, mediaContext))}
199 + onImagePress={(href) =>
200 + setPreview(pullRequestImageSource(resolveMediaUrl(href), mediaContext))
201 + }
202 onTaskListItemPress={props.onTaskListItemPress}
203 />
204 <FilePreviewModal source={preview} onRequestClose={() => setPreview(null)} />
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+2 -2
@@ -106,7 +106,7 @@ import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
106 import type { PullRequestAgentSelectionInput } from "./PullRequestCodeTab";
107 import { openOnHostLabel } from "./pullRequestLinkContextMenu";
108 import { PullRequestMarkdownContext } from "./PullRequestMarkdown";
109 -import { pullRequestAutolinkPlugins } from "./pullRequestMarkdown.logic";
109 +import { pullRequestMarkdownPlugins } from "./pullRequestMarkdown.logic";
110 import { PullRequestComposer } from "./PullRequestComposer";
111 import { PullRequestSummaryTab } from "./PullRequestSummaryTab";
112 import { PullRequestTimelineTab } from "./PullRequestTimelineTab";
@@ -241,7 +241,7 @@ function pullRequestMarkdownContext(
241 threadRef: ScopedThreadRef | null,
242 ) {
243 return {
244 - remarkPlugins: pullRequestAutolinkPlugins(detail),
244 + remarkPlugins: pullRequestMarkdownPlugins(detail),
245 lineBreaks: sourceControlClients.find(detail?.provider ?? "")?.hardLineBreaks ?? false,
246 threadRef,
247 repository: detail?.repository ?? null,
apps/web/src/components/pullRequest/pullRequestMarkdown.logic.ts
+23 -9
@@ -1,4 +1,7 @@
1 -import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
1 +import {
2 + changeRequestReferenceAutolinker,
3 + resolveChangeRequestMediaUrl,
4 +} from "@t3tools/client-runtime/pull-request-markdown";
5 import {
6 sourceControlClients,
7 type ReferenceAutolink,
@@ -58,26 +61,37 @@ export function remarkPullRequestAutolinks(options: {
61 return (tree: MarkdownNode) => visit(tree);
62 }
63
61 -const NO_AUTOLINK_PLUGINS: PluggableList = [];
62 -const autolinkPlugins = new Map<string, PluggableList>();
64 +function remarkChangeRequestMediaUrls(options: { readonly changeRequestUrl: string }) {
65 + const visit = (node: MarkdownNode): void => {
66 + if ((node.type === "image" || node.type === "definition") && node.url !== undefined) {
67 + node.url = resolveChangeRequestMediaUrl(node.url, options.changeRequestUrl);
68 + }
69 + node.children?.forEach(visit);
70 + };
71 + return (tree: MarkdownNode) => visit(tree);
72 +}
73 +
74 +const NO_PLUGINS: PluggableList = [];
75 +const markdownPlugins = new Map<string, PluggableList>();
76
77 /**
78 * One plugin list per repository, so every comment of a pull request shares one markdown
79 * renderer and its parse cache instead of parsing again on each render.
80 */
68 -export function pullRequestAutolinkPlugins(
81 +export function pullRequestMarkdownPlugins(
82 changeRequest: { readonly provider: string; readonly url: string } | null,
83 ): PluggableList {
71 - if (changeRequest === null) return NO_AUTOLINK_PLUGINS;
84 + if (changeRequest === null) return NO_PLUGINS;
85 const repositoryUrl = sourceControlClients.parseChangeRequestUrl(changeRequest.url)?.link
86 .repositoryUrl;
74 - if (repositoryUrl === undefined) return NO_AUTOLINK_PLUGINS;
87 + if (repositoryUrl === undefined) return NO_PLUGINS;
88 const key = `${changeRequest.provider}\u0000${repositoryUrl}`;
76 - let plugins = autolinkPlugins.get(key);
89 + let plugins = markdownPlugins.get(key);
90 if (plugins === undefined) {
91 const autolinks = changeRequestReferenceAutolinker(changeRequest);
79 - plugins = autolinks ? [[remarkPullRequestAutolinks, { autolinks }]] : NO_AUTOLINK_PLUGINS;
80 - autolinkPlugins.set(key, plugins);
92 + plugins = [[remarkChangeRequestMediaUrls, { changeRequestUrl: repositoryUrl }]];
93 + if (autolinks) plugins.push([remarkPullRequestAutolinks, { autolinks }]);
94 + markdownPlugins.set(key, plugins);
95 }
96 return plugins;
97 }
packages/client-runtime/src/pullRequestMarkdown.test.ts
+20 -1
@@ -1,6 +1,10 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { changeRequestReferenceAutolinker, splitPullRequestBody } from "./pullRequestMarkdown.ts";
3 +import {
4 + changeRequestReferenceAutolinker,
5 + resolveChangeRequestMediaUrl,
6 + splitPullRequestBody,
7 +} from "./pullRequestMarkdown.ts";
8
9 describe("pull request body segmentation", () => {
10 // GitHub writes a dropped image into the body as an `<img>` tag, so a bare attachment link on
@@ -157,3 +161,18 @@ describe("change request reference autolinks", () => {
161 expect(urls("forgejo", "https://codeberg.org/acme/web/pulls/7", "#5")).toBeNull();
162 });
163 });
164 +
165 +describe("change request media urls", () => {
166 + // regression: GitCafe's `/api/attachments/<id>` uploads rendered as missing local files
167 + it.each([
168 + ["/api/attachments/attach_1", "https://git.cafe/api/attachments/attach_1"],
169 + ["//cdn.example.com/a.png", "//cdn.example.com/a.png"],
170 + ["/\\evil.example.com/a.png", "/\\evil.example.com/a.png"],
171 + ["https://example.com/a.png", "https://example.com/a.png"],
172 + ["docs/a.png", "docs/a.png"],
173 + ])("resolves %s against the forge", (url, expected) => {
174 + expect(resolveChangeRequestMediaUrl(url, "https://git.cafe/pingdotgg/t3code/pulls/31251")).toBe(
175 + expected,
176 + );
177 + });
178 +});
packages/client-runtime/src/pullRequestMarkdown.ts
+13
@@ -163,3 +163,16 @@ export function changeRequestReferenceAutolinker(
163 ? null
164 : (text) => find(text, repositoryUrl);
165 }
166 +
167 +/**
168 + * Forges link uploads root-relative, as GitCafe's `/api/attachments/<id>`. In a change request
169 + * body that always means the forge's origin, never a path on the machine rendering it.
170 + */
171 +export function resolveChangeRequestMediaUrl(url: string, changeRequestUrl: string): string {
172 + if (!/^\/(?![/\\])/u.test(url)) return url;
173 + try {
174 + return new URL(url, changeRequestUrl).href;
175 + } catch {
176 + return url;
177 + }
178 +}