Skip to content

Commit ed6ebd3

Browse files
Yash-Singh1claude
andcommitted
feat: PR links reach reply-only reviews and unchanged lines, and preview comments and commits
- A link to a review with no text of its own now lands on the comment it posted. GitHub review-thread comments carry their review's URL (optional `reviewUrl`), and a shared helper resolves the review anchor. - A changed-line link to an unchanged line of a patch-only diff expands the file through the viewer's own expander, which loads its contents, then positions the line. A reveal survives the viewer remounting for the same diff. - Hovering a comment or commit link on web and desktop shows that comment or commit instead of the pull request summary; other links keep the pull request card. - Mobile marks the linked comment and reply, and holds the linked comment under the app bar while the rows above it measure in. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a1aabe2 commit ed6ebd3

19 files changed

Lines changed: 482 additions & 36 deletions

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
parsePullRequestAnchor,
33
pullRequestAnchorMatchesUrl,
4+
resolvePullRequestReviewAnchor,
45
} from "@t3tools/shared/pullRequestAnchor";
56
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
67
import { useAtomRefresh } from "@effect/atom-react";
@@ -145,7 +146,11 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
145146
const scrollRef = useRef<ScrollViewInstance>(null);
146147
const pendingTop = useRef<number | null>(null);
147148
const positionedComment = useRef<string | null>(null);
148-
const anchor = parsePullRequestAnchor(params.navigationUrl);
149+
const location = parsePullRequestAnchor(params.navigationUrl);
150+
const anchor =
151+
location?.kind === "timeline"
152+
? resolvePullRequestReviewAnchor(location.anchor, [], [{ comments }])
153+
: null;
149154
const canReply = permissions.canReply && Boolean(thread);
150155
const resolveLabel = thread?.isResolved ? "Unresolve" : "Resolve";
151156
return (
@@ -218,16 +223,20 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
218223
key={comment.id}
219224
onLayout={(event) => {
220225
if (
221-
anchor?.kind !== "timeline" ||
222-
!pullRequestAnchorMatchesUrl(anchor.anchor, comment.url) ||
226+
anchor === null ||
227+
!pullRequestAnchorMatchesUrl(anchor, comment.url) ||
223228
positionedComment.current === comment.id
224229
)
225230
return;
226231
positionedComment.current = comment.id;
227232
pendingTop.current = event.nativeEvent.layout.y;
228233
scrollRef.current?.scrollTo({ y: pendingTop.current, animated: false });
229234
}}
230-
className="gap-3 border-b border-border-subtle py-4"
235+
className={
236+
anchor !== null && pullRequestAnchorMatchesUrl(anchor, comment.url)
237+
? "-mx-3 gap-3 rounded-2xl border border-primary bg-primary/10 px-3 py-4"
238+
: "gap-3 border-b border-border-subtle py-4"
239+
}
231240
>
232241
<View className="flex-row items-center gap-2">
233242
<PullRequestAvatar actor={comment.author} size={28} />

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
pullRequestAnchorMatchesUrl,
44
pullRequestDiffPathMatches,
55
pullRequestLinkCommit,
6+
resolvePullRequestReviewAnchor,
67
} from "@t3tools/shared/pullRequestAnchor";
78
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
89
import { Chip } from "../../components/ui/Chip";
@@ -161,7 +162,16 @@ function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityF
161162
return rows;
162163
})();
163164
const location = parsePullRequestAnchor(params.navigationUrl);
164-
const anchor = location?.kind === "timeline" ? location.anchor : null;
165+
const anchor =
166+
location?.kind !== "timeline"
167+
? null
168+
: result.data
169+
? resolvePullRequestReviewAnchor(
170+
location.anchor,
171+
result.data.comments,
172+
result.data.reviewThreads,
173+
)
174+
: location.anchor;
165175
const targetComment = anchor
166176
? result.data?.comments.find((comment) => pullRequestAnchorMatchesUrl(anchor, comment.url))
167177
: null;
@@ -454,6 +464,15 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
454464
);
455465
const openedDiscussion = useRef<string | null>(null);
456466
const positionedActivity = useRef<string | null>(null);
467+
// Rows above the target measure in after the first jump, so it is held until the user scrolls.
468+
const heldActivityRow = useRef<number | null>(null);
469+
const positionActivityRow = (index: number) =>
470+
void scrollViews.current.activity?.scrollToIndex({
471+
index,
472+
viewPosition: 0,
473+
viewOffset: contentTopInset + 12,
474+
animated: false,
475+
});
457476
const revealActivity = useEffectEvent(() => {
458477
const key = `${params.navigationUrl}:${params.navigationId ?? 0}`;
459478
if (activityContent.targetThread && openedDiscussion.current !== key) {
@@ -467,11 +486,9 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
467486
// Later filter or refresh changes move the row; they must not pull the user back to it.
468487
if (activityTargetIndex >= 0 && positionedActivity.current !== key) {
469488
positionedActivity.current = key;
470-
void scrollViews.current.activity?.scrollToIndex({
471-
index: activityTargetIndex + 1,
472-
viewPosition: 0.5,
473-
animated: false,
474-
});
489+
// Its top sits under the app bar; centering a long comment pushed its start off screen.
490+
heldActivityRow.current = activityTargetIndex + 1;
491+
positionActivityRow(activityTargetIndex + 1);
475492
}
476493
});
477494
const targetThreadId = activityContent.targetThread?.id;
@@ -690,6 +707,13 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
690707
// The scroll view owns its resting offset. LegendList keeps the first
691708
// initialScrollOffset it gets, and the first render has the window's top
692709
// inset (0 on the folded iPhone Duo), not the header's.
710+
onScrollBeginDrag={
711+
tab === "activity"
712+
? () => {
713+
heldActivityRow.current = null;
714+
}
715+
: undefined
716+
}
693717
onScroll={(event) => {
694718
const offset = event.nativeEvent.contentOffset.y;
695719
scrollOffsets.current[tab] = offset;
@@ -713,6 +737,13 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
713737
alwaysBounceVertical
714738
scrollsToTop={section === tab}
715739
onItemSizeChanged={({ itemKey }) => {
740+
const held = heldActivityRow.current;
741+
if (tab === "activity" && held !== null) {
742+
// A filter or refresh that moved the row ends the hold.
743+
if (held !== activityTargetIndex + 1) heldActivityRow.current = null;
744+
else positionActivityRow(held);
745+
return;
746+
}
716747
if (
717748
tab !== "overview" ||
718749
section !== "overview" ||

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ function TimelineComment({
7878
params: PullRequestParams;
7979
actions: CommentActions;
8080
}) {
81-
const [expanded, setExpanded] = useState(() => {
82-
const target = parsePullRequestAnchor(params.navigationUrl);
83-
return target?.kind === "timeline" && pullRequestAnchorMatchesUrl(target.anchor, comment.url);
84-
});
81+
const target = parsePullRequestAnchor(params.navigationUrl);
82+
const linked =
83+
target?.kind === "timeline" && pullRequestAnchorMatchesUrl(target.anchor, comment.url);
84+
const [expanded, setExpanded] = useState(linked);
8585
const { themeVariables: colors } = useAppearancePreferences();
8686
const long = comment.body.length > 450 || comment.body.split("\n").length > 8;
8787
const content = useMemo(
@@ -115,7 +115,13 @@ function TimelineComment({
115115
</Text>
116116
) : null}
117117
{preview.trim() || content.attachments.length ? (
118-
<View className="gap-2 overflow-hidden rounded-2xl bg-grouped-card p-3">
118+
<View
119+
className={
120+
linked
121+
? "gap-2 overflow-hidden rounded-2xl border border-primary bg-primary/10 p-3"
122+
: "gap-2 overflow-hidden rounded-2xl bg-grouped-card p-3"
123+
}
124+
>
119125
<View style={long && !expanded ? { maxHeight: 240, overflow: "hidden" } : undefined}>
120126
<PullRequestMarkdown
121127
markdown={long && !expanded ? comment.body.slice(0, 1200) : comment.body}

‎apps/web/src/components/diffs/useCodeViewFileReveal.test.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,47 @@ describe("createCodeViewFileReveal", () => {
9191
expect(view.scrolls.at(-1)).toEqual({ type: "range", id: "a", range, align: "center" });
9292
});
9393

94-
it("drops a pending reveal when its viewer detaches, but repositions a range a remount loses", () => {
94+
it("expands a patch-only file to an unchanged line before positioning it", () => {
95+
const reveal = createCodeViewFileReveal();
96+
const view = viewer(["a"]);
97+
let partial = true;
98+
const expanded: unknown[] = [];
99+
const instance = {
100+
getDiffForSearch: () =>
101+
({
102+
isPartial: partial,
103+
hunks: [{ additionStart: 10, additionCount: 5, deletionStart: 10, deletionCount: 5 }],
104+
}) as never,
105+
expandHunk: (...args: unknown[]) => expanded.push(args),
106+
revealLine: () => false,
107+
getLinePosition: () => ({ top: 100, height: 20 }),
108+
};
109+
reveal.attach({
110+
...view,
111+
getInstance: () => ({ getRenderedItems: () => [{ id: "a", instance }] }),
112+
});
113+
const range = { start: 30, end: 30, side: "additions" } as const;
114+
reveal.request("a", range);
115+
expect(expanded).toEqual([[1, "up", 26]]);
116+
reveal.flush();
117+
expect(view.scrolls).toEqual([]);
118+
// The expander loads the file; the next render holds the line.
119+
partial = false;
120+
reveal.flush();
121+
expect(view.scrolls).toEqual([{ type: "range", id: "a", range, align: "center" }]);
122+
});
123+
124+
it("drops a pending reveal when another diff's viewer replaces it, but repositions a range a remount loses", () => {
95125
const reveal = createCodeViewFileReveal();
96126
const first = viewer([]);
97-
const second = viewer(["a"]);
127+
// Item ids carry the diff's scope, so another diff's viewer holds other ids.
128+
const second = viewer(["b"]);
98129
reveal.attach(first);
99130

100131
reveal.request("a");
101132
reveal.attach(null);
102133
reveal.attach(second);
134+
second.items.add("a");
103135
reveal.flush();
104136
expect(second.scrolls).toEqual([]);
105137

‎apps/web/src/components/diffs/useCodeViewFileReveal.ts‎

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface FileRevealHandle {
1414
instance: {
1515
getDiffForSearch?(): FileDiffMetadata | undefined;
1616
revealLine?(line: number): boolean;
17+
expandHunk?(hunkIndex: number, direction: "up" | "down", lineCount: number): void;
1718
getLinePosition(
1819
line: number,
1920
side?: SelectionSide,
@@ -26,18 +27,47 @@ interface FileRevealHandle {
2627
scrollTo(target: CodeViewScrollTarget): void;
2728
}
2829

30+
// Mirrors the viewer's `revealLine`, which reads distances from the edges of the collapsed gap.
31+
function expandPartialDiffToLine(
32+
diff: FileDiffMetadata,
33+
line: number,
34+
expandHunk: (hunkIndex: number, direction: "up" | "down", lineCount: number) => void,
35+
): boolean {
36+
const { hunks } = diff;
37+
if (
38+
hunks.some(
39+
(hunk) => line >= hunk.additionStart && line < hunk.additionStart + hunk.additionCount,
40+
)
41+
) {
42+
return false;
43+
}
44+
const next = hunks.findIndex((hunk) => line < hunk.additionStart);
45+
const previous = next === -1 ? hunks.at(-1) : hunks[next - 1];
46+
const fromStart = line - (previous ? previous.additionStart + previous.additionCount : 1) + 1;
47+
const after = next === -1 ? undefined : hunks[next];
48+
if (after === undefined) expandHunk(hunks.length, "up", fromStart + REVEAL_CONTEXT_LINES);
49+
else if (fromStart <= after.additionStart - line) {
50+
expandHunk(next, "up", fromStart + REVEAL_CONTEXT_LINES);
51+
} else expandHunk(next, "down", after.additionStart - line + REVEAL_CONTEXT_LINES);
52+
return true;
53+
}
54+
55+
const REVEAL_CONTEXT_LINES = 10;
56+
2957
/**
3058
* Scrolls a code view to a file. `attach` is the viewer's ref and `flush` its post-render
3159
* handler, so a reveal asked before the viewer mounts, or for a file it does not hold yet, is
32-
* positioned once it does. A reveal belongs to the diff it was asked of, so detaching the viewer,
33-
* such as remounting it for another diff scope, drops it.
60+
* positioned once it does. A reveal belongs to the diff it was asked of, so a viewer remounted for
61+
* another diff scope, which no longer holds the file, drops it.
3462
*/
3563
export function createCodeViewFileReveal() {
3664
let viewer: FileRevealHandle | null = null;
65+
let detachedInstance: object | undefined;
3766
let pending: {
3867
id: string;
3968
range?: SelectedLineRange;
4069
positionedFile?: boolean;
70+
loadingFile?: boolean;
4171
settling?: boolean;
4272
} | null = null;
4373
const flush = () => {
@@ -70,10 +100,24 @@ export function createCodeViewFileReveal() {
70100
: line;
71101
};
72102
const { range } = pending;
73-
const startExpanded = rendered.instance.revealLine?.(additionLine(range.start, range.side));
74-
const endExpanded = rendered.instance.revealLine?.(
75-
additionLine(range.end, range.endSide ?? range.side),
76-
);
103+
const startLine = additionLine(range.start, range.side);
104+
const endLine = additionLine(range.end, range.endSide ?? range.side);
105+
// A patch-only diff holds no unchanged lines, and `revealLine` declines to expand it. The
106+
// viewer's own expander loads the file first, so a line outside every hunk is opened with it.
107+
if (diff?.isPartial && rendered.instance.expandHunk) {
108+
// Wait for the file contents the expander asked for.
109+
if (pending.loadingFile) return;
110+
const { expandHunk } = rendered.instance;
111+
const opened = [...new Set([startLine, endLine])].map((line) =>
112+
expandPartialDiffToLine(diff, line, expandHunk),
113+
);
114+
if (opened.some(Boolean)) {
115+
pending.loadingFile = true;
116+
return;
117+
}
118+
}
119+
const startExpanded = rendered.instance.revealLine?.(startLine);
120+
const endExpanded = rendered.instance.revealLine?.(endLine);
77121
if (startExpanded || endExpanded) return;
78122
if (
79123
!rendered.instance.getLinePosition(range.start, range.side) ||
@@ -93,7 +137,19 @@ export function createCodeViewFileReveal() {
93137
};
94138
return {
95139
attach(next: FileRevealHandle | null) {
96-
if (viewer !== null && next !== viewer && !pending?.settling) pending = null;
140+
// The viewer rebuilds its handle on every render and can remount during the diff's first
141+
// load. Item ids carry the diff's scope, so only a viewer without the item drops the reveal.
142+
const previous = viewer?.getInstance() ?? detachedInstance;
143+
if (next === null) detachedInstance = previous;
144+
else {
145+
const instance = next.getInstance();
146+
if (pending !== null && previous !== undefined && instance !== previous) {
147+
if (instance === undefined || next.getItem(pending.id) === undefined) pending = null;
148+
// A new instance starts from the patch again, so it must expand the line itself.
149+
else pending.loadingFile = false;
150+
}
151+
detachedInstance = undefined;
152+
}
97153
viewer = next;
98154
flush();
99155
},

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
parsePullRequestAnchor,
33
pullRequestLinkCommit,
4+
resolvePullRequestReviewAnchor,
45
type PullRequestAnchor,
56
} from "@t3tools/shared/pullRequestAnchor";
67
import { projectChangeRequestUrl } from "@t3tools/client-runtime/change-request-links";
@@ -673,7 +674,16 @@ export function PullRequestDetailPanel({
673674
const refreshFromHost = async () => {
674675
await refetchFromHost();
675676
};
676-
const timelineAnchor = revealAnchor?.kind === "timeline" ? revealAnchor.anchor : null;
677+
const timelineAnchor =
678+
revealAnchor?.kind !== "timeline"
679+
? null
680+
: detail === null
681+
? revealAnchor.anchor
682+
: resolvePullRequestReviewAnchor(
683+
revealAnchor.anchor,
684+
detail.comments,
685+
detail.reviewThreads,
686+
);
677687
// Loaded activity without the linked item, keyed by load so a refetch is checked again.
678688
const revealMissedAt =
679689
timelineAnchor !== null &&

0 commit comments

Comments
 (0)