Skip to content

Commit e428a2c

Browse files
CodyRayclaudemaria-rcks
authored
fix(web,mobile): pull request text breaks lines when providers do (#26060)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 7f2ff41 commit e428a2c

12 files changed

Lines changed: 82 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.find(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
@@ -188,7 +188,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
188188
<>
189189
<GuideNotice state={state} />
190190
<Text className="text-2xl leading-8 font-t3-semibold">{stop.title}</Text>
191-
<PullRequestMarkdown markdown={stop.summary} />
191+
<PullRequestMarkdown lineBreaks={false} markdown={stop.summary} />
192192
{stop.attention ? (
193193
<View className="gap-3 rounded-xl border border-border bg-grouped-card p-4">
194194
<View className="flex-row items-center gap-2">
@@ -197,7 +197,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
197197
{attentionLabels[stop.attention.kind]}
198198
</Text>
199199
</View>
200-
<PullRequestMarkdown markdown={stop.attention.note} />
200+
<PullRequestMarkdown lineBreaks={false} markdown={stop.attention.note} />
201201
</View>
202202
) : null}
203203
{stale ? (
@@ -237,7 +237,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
237237
<Text className="text-xs text-foreground-muted">
238238
{note.path.split("/").at(-1)}:{note.line}
239239
</Text>
240-
<PullRequestMarkdown markdown={note.body} />
240+
<PullRequestMarkdown lineBreaks={false} markdown={note.body} />
241241
</View>
242242
</View>
243243
))}
@@ -266,7 +266,7 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
266266
<View className="gap-3">
267267
<Text className="font-t3-semibold">Questions to consider</Text>
268268
{stop.questions.map((question) => (
269-
<PullRequestMarkdown key={question} markdown={question} />
269+
<PullRequestMarkdown key={question} lineBreaks={false} markdown={question} />
270270
))}
271271
</View>
272272
) : 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.find(detail?.provider ?? "")?.hardLineBreaks ?? false,
245+
threadRef,
246+
};
243247
}
244248

245249
function pullRequestStackReference(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.each(["github", "forgejo", "azure-devops"])("%s breaks a single newline", async (host) => {
27+
await using screen = await renderBody(host);
28+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
29+
expect(screen.container.querySelectorAll("p br")).toHaveLength(1);
30+
});
31+
32+
it.each(["gitlab", "bitbucket", "gitcafe", "unknown"])(
33+
"%s joins a single newline",
34+
async (host) => {
35+
await using screen = await renderBody(host);
36+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
37+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
38+
},
39+
);
40+
41+
it("lets text the host did not write opt out of the host's breaks", async () => {
42+
await using screen = await renderBody("github", { lineBreaks: false });
43+
await expect.element(screen.getByText(/first line/)).toBeInTheDocument();
44+
expect(screen.container.querySelectorAll("p br")).toHaveLength(0);
45+
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const definition = defineSourceControl({
117117
changeRequestCloseCommand:
118118
/\baz\s+repos\s+pr\s+update\b[^;&|]*--status[\s=]+["']?(?:completed|abandoned)\b/u,
119119
authorProfileUrl: () => null,
120+
hardLineBreaks: true,
120121
reviewSummaryRequired: () => false,
121122
checkoutCommandArgument: (input) => {
122123
const args = CHECKOUT_COMMAND.exec(input)?.[1];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ export interface SourceControlDefinition {
286286
text: string,
287287
repositoryUrl: string,
288288
) => ReadonlyArray<ReferenceAutolink>;
289+
/** True when the host renders a single newline in change request text as a line break. */
290+
readonly hardLineBreaks?: boolean;
289291
/** Where the host lists a change request's checks. Absent means the change request's own page. */
290292
readonly changeRequestChecksUrl?: (changeRequestUrl: string) => string;
291293
/**

0 commit comments

Comments
 (0)