Skip to content

Commit b124f23

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. Hosts that break on a newline now say so in their definition, 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 5211acf commit b124f23

12 files changed

Lines changed: 79 additions & 9 deletions

File tree

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

Lines changed: 14 additions & 2 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, 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";
@@ -31,6 +34,7 @@ import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText"
3134
const AutolinksContext = createContext<((text: string) => ReadonlyArray<ReferenceAutolink>) | null>(
3235
null,
3336
);
37+
const LineBreaksContext = createContext(false);
3438

3539
export function PullRequestMarkdownRepository(props: {
3640
/** The change request the markdown belongs to, whose host decides what its text links. */
@@ -44,6 +48,7 @@ export function PullRequestMarkdownRepository(props: {
4448
provider === undefined || url === undefined
4549
? null
4650
: changeRequestReferenceAutolinker({ provider, url });
51+
const lineBreaks = sourceControlClients.get(provider).hardLineBreaks ?? false;
4752
const target = pullRequestTarget(props.params);
4853
const project = useProject({
4954
environmentId: target.environmentId,
@@ -53,7 +58,9 @@ export function PullRequestMarkdownRepository(props: {
5358
const media = cwd ? { environmentId: target.environmentId, cwd } : null;
5459
return (
5560
<AutolinksContext value={autolinks}>
56-
<PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
61+
<LineBreaksContext value={lineBreaks}>
62+
<PullRequestMediaContext value={media}>{props.children}</PullRequestMediaContext>
63+
</LineBreaksContext>
5764
</AutolinksContext>
5865
);
5966
}
@@ -88,6 +95,7 @@ function MarkdownImage(props: {
8895
export function PullRequestMarkdown(props: {
8996
readonly markdown: string;
9097
readonly imageGroupMarkdown?: string;
98+
readonly lineBreaks?: boolean;
9199
}) {
92100
const segments = useMemo(() => splitPullRequestBody(props.markdown), [props.markdown]);
93101
return (
@@ -98,6 +106,7 @@ export function PullRequestMarkdown(props: {
98106
key={segment.id}
99107
markdown={segment.text}
100108
imageGroupMarkdown={props.imageGroupMarkdown ?? props.markdown}
109+
lineBreaks={props.lineBreaks}
101110
/>
102111
) : (
103112
<PullRequestMedia key={segment.id} url={segment.url} kind={segment.media} />
@@ -110,7 +119,9 @@ export function PullRequestMarkdown(props: {
110119
function PullRequestMarkdownContent(props: {
111120
readonly markdown: string;
112121
readonly imageGroupMarkdown?: string;
122+
readonly lineBreaks: boolean | undefined;
113123
}) {
124+
const hostLineBreaks = useContext(LineBreaksContext);
114125
const autolinks = useContext(AutolinksContext);
115126
const mediaContext = useContext(PullRequestMediaContext);
116127
const markdown = linkReferenceAutolinks(props.markdown, autolinks);
@@ -136,6 +147,7 @@ function PullRequestMarkdownContent(props: {
136147
<FilePreviewGallery value={gallery}>
137148
<SelectableMarkdownText
138149
markdown={markdown}
150+
preserveSoftBreaks={props.lineBreaks ?? hostLineBreaks}
139151
textStyle={styles.nativeTextStyle}
140152
onLinkPress={openLink}
141153
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
@@ -182,7 +182,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
182182
<>
183183
<GuideNotice state={state} />
184184
<Text className="text-2xl leading-8 font-t3-semibold">{stop.title}</Text>
185-
<PullRequestMarkdown markdown={stop.summary} />
185+
<PullRequestMarkdown lineBreaks={false} markdown={stop.summary} />
186186
{stop.attention ? (
187187
<View className="gap-3 rounded-xl border border-border bg-grouped-card p-4">
188188
<View className="flex-row items-center gap-2">
@@ -191,7 +191,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
191191
{attentionLabels[stop.attention.kind]}
192192
</Text>
193193
</View>
194-
<PullRequestMarkdown markdown={stop.attention.note} />
194+
<PullRequestMarkdown lineBreaks={false} markdown={stop.attention.note} />
195195
</View>
196196
) : null}
197197
{stale ? (
@@ -231,7 +231,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
231231
<Text className="text-xs text-foreground-muted">
232232
{note.path.split("/").at(-1)}:{note.line}
233233
</Text>
234-
<PullRequestMarkdown markdown={note.body} />
234+
<PullRequestMarkdown lineBreaks={false} markdown={note.body} />
235235
</View>
236236
</View>
237237
))}
@@ -260,7 +260,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
260260
<View className="gap-3">
261261
<Text className="font-t3-semibold">Questions to consider</Text>
262262
{stop.questions.map((question) => (
263-
<PullRequestMarkdown key={question} markdown={question} />
263+
<PullRequestMarkdown key={question} lineBreaks={false} markdown={question} />
264264
))}
265265
</View>
266266
) : 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ function pullRequestMarkdownContext(
239239
detail: Pick<PullRequestDetail, "provider" | "url"> | null,
240240
threadRef: ScopedThreadRef | null,
241241
) {
242-
return { autolinks: changeRequestReferenceAutolinker(detail), threadRef };
242+
return {
243+
autolinks: changeRequestReferenceAutolinker(detail),
244+
lineBreaks: sourceControlClients.get(detail?.provider).hardLineBreaks ?? false,
245+
threadRef,
246+
};
243247
}
244248

245249
function pullRequestStackReference(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2+
import { EnvironmentId } from "@t3tools/contracts";
3+
import { expect, it } from "vite-plus/test";
4+
5+
import { render } from "../../../test/render";
6+
import { PullRequestMarkdown, PullRequestMarkdownContext } from "./PullRequestMarkdown";
7+
8+
async function renderBody(host: string, options: { lineBreaks?: boolean } = {}) {
9+
const context = {
10+
autolinks: null,
11+
lineBreaks: sourceControlClients.get(host).hardLineBreaks ?? false,
12+
threadRef: null,
13+
};
14+
return render(
15+
<PullRequestMarkdownContext value={context}>
16+
<PullRequestMarkdown
17+
text={"first line\nsecond line"}
18+
cwd="/repo"
19+
environmentId={EnvironmentId.make("local")}
20+
{...options}
21+
/>
22+
</PullRequestMarkdownContext>,
23+
);
24+
}
25+
26+
it("breaks a single newline where the host does", async () => {
27+
await using screen = await renderBody("github");
28+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
29+
expect(screen.container.querySelectorAll("p br")).toHaveLength(1);
30+
});
31+
32+
it("joins a single newline into the paragraph where the host does", async () => {
33+
await using screen = await renderBody("gitlab");
34+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
35+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
36+
});
37+
38+
it("lets text the host did not write opt out of the host's breaks", async () => {
39+
await using screen = await renderBody("github", { lineBreaks: false });
40+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
41+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
42+
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { remarkPullRequestAutolinks, splitPullRequestBody } from "./pullRequestM
2323

2424
export const PullRequestMarkdownContext = createContext<{
2525
autolinks: ((text: string) => ReadonlyArray<ReferenceAutolink>) | null;
26+
lineBreaks: boolean;
2627
threadRef: ScopedThreadRef | null;
2728
} | null>(null);
2829

@@ -59,12 +60,14 @@ export function PullRequestMarkdown({
5960
cwd,
6061
environmentId,
6162
threadRef,
63+
lineBreaks,
6264
className,
6365
}: {
6466
text: string;
6567
cwd: string;
6668
environmentId: EnvironmentId;
6769
threadRef?: ScopedThreadRef | null;
70+
lineBreaks?: boolean;
6871
className?: string;
6972
}) {
7073
const segments = splitPullRequestBody(text);
@@ -93,6 +96,7 @@ export function PullRequestMarkdown({
9396
pullRequestPanelRef={resolvedThreadRef ?? PULL_REQUESTS_PANEL_REF}
9497
environmentId={environmentId}
9598
extraRemarkPlugins={extraRemarkPlugins}
99+
lineBreaks={lineBreaks ?? context?.lineBreaks ?? false}
96100
sourceControlMedia
97101
/>
98102
);

‎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-core/src/shared/definition.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ export interface SourceControlDefinition {
272272
text: string,
273273
repositoryUrl: string,
274274
) => ReadonlyArray<ReferenceAutolink>;
275+
/** True when the host renders a single newline in change request text as a line break. */
276+
readonly hardLineBreaks?: boolean;
275277
/** Where the host lists a change request's checks. Absent means the change request's own page. */
276278
readonly changeRequestChecksUrl?: (changeRequestUrl: string) => string;
277279
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const definition = defineSourceControl({
9191
changeRequestCloseCommand: /\b(?:tea\s+(?:pr|pulls)|fj\s+pr)\s+(?:merge|close)\b/u,
9292
authorProfileUrl: () => null,
9393
// Forgejo refuses a change request review without a summary, even with inline comments.
94+
hardLineBreaks: true,
9495
reviewSummaryRequired: (verdict) => verdict === "request-changes",
9596
checkoutCommandArgument: (input) => CHECKOUT_COMMAND.exec(input)?.[1]?.trim() ?? null,
9697
isChangeRequestReference: (url) => CHANGE_REQUEST_REFERENCE.test(url),

0 commit comments

Comments
 (0)