Skip to content

Commit b7ff9ff

Browse files
CodyRayclaude
andcommitted
fix(web,mobile): pull request text breaks lines where its host does
GitHub renders a single newline in a pull request description or comment as a line break, but T3 Code rendered it with plain markdown rules, so descriptions written on GitHub ran their lines together. Hosts disagree: GitHub and Forgejo break on a newline in change request text, while GitLab, Bitbucket, and Azure DevOps follow CommonMark. Each host definition now declares the rule, and the pull request renderers on web and mobile follow it. Review guide prose is written by an agent, not on the host, so it opts out and keeps chat's markdown rules. GitCafe is assumed to match GitHub, since it syncs pull requests with GitHub. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent dc84b09 commit b7ff9ff

15 files changed

Lines changed: 106 additions & 24 deletions

File tree

‎apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
import { videoMimeType } from "@t3tools/shared/video";
1212
import { createContext, useContext, useCallback, useMemo, useState } from "react";
1313
import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
14-
import type { ReferenceAutolink } from "@t3tools/client-runtime/source-control-clients";
14+
import {
15+
sourceControlClients,
16+
type ReferenceAutolink,
17+
} from "@t3tools/client-runtime/source-control-clients";
1518
import { linkReferenceAutolinks } from "./pullRequestAutolinks";
1619

1720
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
@@ -28,9 +31,10 @@ import {
2831
import { ThreadMarkdownImageView } from "../threads/ThreadMarkdownImage";
2932
import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText";
3033

31-
const AutolinksContext = createContext<((text: string) => ReadonlyArray<ReferenceAutolink>) | null>(
32-
null,
33-
);
34+
const HostTextContext = createContext<{
35+
readonly autolinks: ((text: string) => ReadonlyArray<ReferenceAutolink>) | null;
36+
readonly lineBreaks: boolean;
37+
} | null>(null);
3438

3539
export function PullRequestMarkdownRepository(props: {
3640
/** The change request the markdown belongs to, whose host decides what its text links. */
@@ -40,11 +44,14 @@ export function PullRequestMarkdownRepository(props: {
4044
}) {
4145
const provider = props.changeRequest?.provider;
4246
const url = props.changeRequest?.url;
43-
const autolinks = useMemo(
47+
const hostText = useMemo(
4448
() =>
4549
provider === undefined || url === undefined
4650
? null
47-
: changeRequestReferenceAutolinker({ provider, url }),
51+
: {
52+
autolinks: changeRequestReferenceAutolinker({ provider, url }),
53+
lineBreaks: sourceControlClients.get(provider).hardLineBreaks,
54+
},
4855
[provider, url],
4956
);
5057
const target = pullRequestTarget(props.params);
@@ -58,9 +65,9 @@ export function PullRequestMarkdownRepository(props: {
5865
[target.environmentId, cwd],
5966
);
6067
return (
61-
<AutolinksContext value={autolinks}>
68+
<HostTextContext value={hostText}>
6269
<PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
63-
</AutolinksContext>
70+
</HostTextContext>
6471
);
6572
}
6673

@@ -94,6 +101,7 @@ function MarkdownImage(props: {
94101
export function PullRequestMarkdown(props: {
95102
readonly markdown: string;
96103
readonly imageGroupMarkdown?: string;
104+
readonly lineBreaks?: boolean;
97105
}) {
98106
const segments = useMemo(() => splitPullRequestBody(props.markdown), [props.markdown]);
99107
return (
@@ -104,6 +112,7 @@ export function PullRequestMarkdown(props: {
104112
key={segment.id}
105113
markdown={segment.text}
106114
imageGroupMarkdown={props.imageGroupMarkdown ?? props.markdown}
115+
lineBreaks={props.lineBreaks}
107116
/>
108117
) : (
109118
<PullRequestMedia key={segment.id} url={segment.url} kind={segment.media} />
@@ -116,8 +125,10 @@ export function PullRequestMarkdown(props: {
116125
function PullRequestMarkdownContent(props: {
117126
readonly markdown: string;
118127
readonly imageGroupMarkdown?: string;
128+
readonly lineBreaks: boolean | undefined;
119129
}) {
120-
const autolinks = useContext(AutolinksContext);
130+
const hostText = useContext(HostTextContext);
131+
const autolinks = hostText?.autolinks ?? null;
121132
const mediaContext = useContext(PullRequestMediaContext);
122133
const markdown = useMemo(
123134
() => linkReferenceAutolinks(props.markdown, autolinks),
@@ -151,6 +162,7 @@ function PullRequestMarkdownContent(props: {
151162
<FilePreviewGallery value={gallery}>
152163
<SelectableMarkdownText
153164
markdown={markdown}
165+
preserveSoftBreaks={props.lineBreaks ?? hostText?.lineBreaks ?? false}
154166
textStyle={styles.nativeTextStyle}
155167
onLinkPress={openLink}
156168
renderImage={renderImage}

‎apps/mobile/src/features/pull-requests/guide/GuideOutline.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function GuideOutline({
5959
</View>
6060
{guide.stops[0]?.summary ? (
6161
<View className="mb-6">
62-
<PullRequestMarkdown markdown={guide.stops[0].summary} />
62+
<PullRequestMarkdown lineBreaks={false} markdown={guide.stops[0].summary} />
6363
</View>
6464
) : null}
6565
{guide.stops.map((stop, position) => {

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
181181
<>
182182
<GuideNotice state={state} />
183183
<Text className="text-2xl leading-8 font-t3-semibold">{stop.title}</Text>
184-
<PullRequestMarkdown markdown={stop.summary} />
184+
<PullRequestMarkdown lineBreaks={false} markdown={stop.summary} />
185185
{stop.attention ? (
186186
<View className="gap-3 rounded-xl border border-border bg-grouped-card p-4">
187187
<View className="flex-row items-center gap-2">
@@ -190,7 +190,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
190190
{attentionLabels[stop.attention.kind]}
191191
</Text>
192192
</View>
193-
<PullRequestMarkdown markdown={stop.attention.note} />
193+
<PullRequestMarkdown lineBreaks={false} markdown={stop.attention.note} />
194194
</View>
195195
) : null}
196196
{stale ? (
@@ -230,7 +230,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
230230
<Text className="text-xs text-foreground-muted">
231231
{note.path.split("/").at(-1)}:{note.line}
232232
</Text>
233-
<PullRequestMarkdown markdown={note.body} />
233+
<PullRequestMarkdown lineBreaks={false} markdown={note.body} />
234234
</View>
235235
</View>
236236
))}
@@ -259,7 +259,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
259259
<View className="gap-3">
260260
<Text className="font-t3-semibold">Questions to consider</Text>
261261
{stop.questions.map((question) => (
262-
<PullRequestMarkdown key={question} markdown={question} />
262+
<PullRequestMarkdown key={question} lineBreaks={false} markdown={question} />
263263
))}
264264
</View>
265265
) : null}

‎apps/mobile/src/features/pull-requests/guide/ReviewGuideExcerpt.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export function ReviewGuideExcerpt({
5555
const [NativeDiff] = useState(() => resolveNativeReviewDiffView());
5656
return (
5757
<View className="gap-3">
58-
{excerpt.caption.trim() ? <PullRequestMarkdown markdown={excerpt.caption} /> : null}
58+
{excerpt.caption.trim() ? (
59+
<PullRequestMarkdown lineBreaks={false} markdown={excerpt.caption} />
60+
) : null}
5961
<View className="overflow-hidden rounded-lg border border-border-subtle">
6062
<Pressable
6163
accessibilityRole="button"

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { projectChangeRequestUrl } from "@t3tools/client-runtime/change-request-links";
22
import { normalizeThreadPullRequestKey } from "@t3tools/client-runtime/thread-pull-requests";
3-
import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
43
import { useAtomValue } from "@effect/atom-react";
54
import { usePullRequestStack } from "~/state/usePullRequestStack";
65
import {
@@ -104,7 +103,7 @@ import { DiffPanelLoadingState } from "../DiffPanelShell";
104103
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
105104
import type { PullRequestAgentSelectionInput } from "./PullRequestCodeTab";
106105
import { openOnHostLabel } from "./pullRequestLinkContextMenu";
107-
import { PullRequestMarkdownContext } from "./PullRequestMarkdown";
106+
import { PullRequestMarkdownContext, pullRequestMarkdownContext } from "./PullRequestMarkdown";
108107
import { PullRequestComposer } from "./PullRequestComposer";
109108
import { PullRequestSummaryTab } from "./PullRequestSummaryTab";
110109
import { PullRequestTimelineTab } from "./PullRequestTimelineTab";
@@ -232,13 +231,6 @@ function resolvePullRequestReference(
232231
};
233232
}
234233

235-
function pullRequestMarkdownContext(
236-
detail: Pick<PullRequestDetail, "provider" | "url"> | null,
237-
threadRef: ScopedThreadRef | null,
238-
) {
239-
return { autolinks: changeRequestReferenceAutolinker(detail), threadRef };
240-
}
241-
242234
function pullRequestStackReference(
243235
detail: Pick<PullRequestDetail, "url" | "capabilities"> | null,
244236
reference: PullRequestRef,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { EnvironmentId, SourceControlProviderKind } from "@t3tools/contracts";
2+
import { expect, it } from "vite-plus/test";
3+
4+
import { render } from "../../../test/render";
5+
import {
6+
PullRequestMarkdown,
7+
PullRequestMarkdownContext,
8+
pullRequestMarkdownContext,
9+
} from "./PullRequestMarkdown";
10+
11+
const hosts = {
12+
github: "https://github.com/owner/repo/pull/1",
13+
gitlab: "https://gitlab.com/owner/repo/-/merge_requests/1",
14+
};
15+
16+
async function renderBody(host: keyof typeof hosts, options: { lineBreaks?: boolean } = {}) {
17+
const context = pullRequestMarkdownContext(
18+
{ provider: SourceControlProviderKind.make(host), url: hosts[host] },
19+
null,
20+
);
21+
return render(
22+
<PullRequestMarkdownContext value={context}>
23+
<PullRequestMarkdown
24+
text={"first line\nsecond line"}
25+
cwd="/repo"
26+
environmentId={EnvironmentId.make("local")}
27+
{...options}
28+
/>
29+
</PullRequestMarkdownContext>,
30+
);
31+
}
32+
33+
it("breaks a single newline where the host does", async () => {
34+
await using screen = await renderBody("github");
35+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
36+
expect(screen.container.querySelectorAll("p br")).toHaveLength(1);
37+
});
38+
39+
it("joins a single newline into the paragraph where the host does", async () => {
40+
await using screen = await renderBody("gitlab");
41+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
42+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
43+
});
44+
45+
it("lets text the host did not write opt out of the host's breaks", async () => {
46+
await using screen = await renderBody("github", { lineBreaks: false });
47+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
48+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
49+
});

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ExternalLinkIcon, PaperclipIcon } from "lucide-react";
22
import { markdownImageSourceFragment } from "@t3tools/client-runtime/markdown-images";
3+
import { changeRequestReferenceAutolinker } from "@t3tools/client-runtime/pull-request-markdown";
34
import {
45
sourceControlClients,
56
type ReferenceAutolink,
@@ -8,6 +9,7 @@ import {
89
SOURCE_CONTROL_MEDIA_ASSET,
910
type AssetResource,
1011
type EnvironmentId,
12+
type PullRequestDetail,
1113
type ScopedThreadRef,
1214
} from "@t3tools/contracts";
1315
import { createContext, useContext } from "react";
@@ -23,9 +25,21 @@ import { remarkPullRequestAutolinks, splitPullRequestBody } from "./pullRequestM
2325

2426
export const PullRequestMarkdownContext = createContext<{
2527
autolinks: ((text: string) => ReadonlyArray<ReferenceAutolink>) | null;
28+
lineBreaks: boolean;
2629
threadRef: ScopedThreadRef | null;
2730
} | null>(null);
2831

32+
export function pullRequestMarkdownContext(
33+
detail: Pick<PullRequestDetail, "provider" | "url"> | null,
34+
threadRef: ScopedThreadRef | null,
35+
) {
36+
return {
37+
autolinks: changeRequestReferenceAutolinker(detail),
38+
lineBreaks: sourceControlClients.get(detail?.provider).hardLineBreaks,
39+
threadRef,
40+
};
41+
}
42+
2943
function PullRequestHostVideo({
3044
environmentId,
3145
cwd,
@@ -59,12 +73,14 @@ export function PullRequestMarkdown({
5973
cwd,
6074
environmentId,
6175
threadRef,
76+
lineBreaks,
6277
className,
6378
}: {
6479
text: string;
6580
cwd: string;
6681
environmentId: EnvironmentId;
6782
threadRef?: ScopedThreadRef | null;
83+
lineBreaks?: boolean;
6884
className?: string;
6985
}) {
7086
const segments = splitPullRequestBody(text);
@@ -93,6 +109,7 @@ export function PullRequestMarkdown({
93109
pullRequestPanelRef={resolvedThreadRef ?? PULL_REQUESTS_PANEL_REF}
94110
environmentId={environmentId}
95111
extraRemarkPlugins={extraRemarkPlugins}
112+
lineBreaks={lineBreaks ?? context?.lineBreaks ?? false}
96113
sourceControlMedia
97114
/>
98115
);

‎apps/web/src/components/pullRequest/guide/GuideProse.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function GuideProse({
2626
text={text}
2727
cwd={context.cwd}
2828
environmentId={context.environmentId}
29+
lineBreaks={false}
2930
className={cn("space-y-0 [&_.chat-markdown]:text-inherit", className)}
3031
/>
3132
);

‎packages/source-control-azure-devops/src/shared/definition.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const definition = defineSourceControl({
108108
changeRequestCloseCommand:
109109
/\baz\s+repos\s+pr\s+update\b[^;&|]*--status[\s=]+["']?(?:completed|abandoned)\b/u,
110110
authorProfileUrl: () => null,
111+
hardLineBreaks: false,
111112
reviewSummaryRequired: () => false,
112113
checkoutCommandArgument: (input) => {
113114
const args = CHECKOUT_COMMAND.exec(input)?.[1];

‎packages/source-control-bitbucket/src/shared/definition.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const definition = defineSourceControl({
9999
? `git clone --single-branch --branch ${headBranch} https://bitbucket.org/${headRepositoryNameWithOwner}.git t3code-pr-${number}`
100100
: null,
101101
authorProfileUrl: () => null,
102+
hardLineBreaks: false,
102103
reviewSummaryRequired: () => false,
103104
checkoutCommandArgument: () => null,
104105
isChangeRequestReference: () => false,

0 commit comments

Comments
 (0)