GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): PR links jump to the comment, diff line, checks or commits … · pingdotgg/t3code@694903b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • mobile/src
      • features/pull-requests
        • PullRequestDiscussionScreen.tsx
        • PullRequestRouteScreen.tsx
        • PullRequestStatusRows.tsx
        • PullRequestTimeline.tsx
        • guide
          • guideDiffFocus.test.ts
          • guideDiffFocus.ts
        • pullRequestNavigation.test.ts
        • usePullRequestDiff.ts
      • lib
        • pullRequestNavigation.ts
      • native
        • useOpenPullRequest.ts
    • web/src
      • components
        • chat
          • RightPanelSurfaceContent.tsx
        • diffs
          • useCodeViewFileReveal.test.ts
          • useCodeViewFileReveal.ts
        • pullRequest
          • PullRequestCodeTab.browser.test.tsx
          • PullRequestCodeTab.tsx
          • PullRequestDetailPanel.tsx
          • PullRequestSummaryTab.tsx
          • PullRequestTimelineTab.browser.test.tsx
          • PullRequestTimelineTab.tsx
          • PullRequestsPage.tsx
          • holdLinkedNodeInView.ts
          • pullRequestDetail.logic.ts
          • usePullRequestListView.ts
      • lib
        • openPullRequestLink.browser.test.tsx
        • openPullRequestLink.ts
      • rightPanelStore.test.ts
      • rightPanelStore.ts
      • routes
        • _chat.pull-requests.tsx
  • packages/shared
    • package.json
    • src
      • pullRequestAnchor.test.ts
      • pullRequestAnchor.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestDiscussionScreen.tsx
+30-2Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
parsePullRequestAnchor,
3+
pullRequestAnchorMatchesUrl,
4+
} from "@t3tools/shared/pullRequestAnchor";
15
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
26
import { useAtomRefresh } from "@effect/atom-react";
37
import { useFocusEffect, useNavigation, type StaticScreenProps } from "@react-navigation/native";
@@ -8,7 +12,7 @@ import {
812
import { AsyncResult } from "effect/reactivity";
913
import type { PullRequestThreadComment } from "@t3tools/contracts";
1014
import { useRef, useState } from "react";
11-
import { ScrollView, View } from "react-native";
15+
import { ScrollView, View, type ScrollViewInstance } from "react-native";
1216
import { KeyboardAvoidingView, useKeyboardState } from "react-native-keyboard-controller";
1317
import { NativeScrollViewMarker as ScrollViewMarker } from "../../native/NativeScrollViewMarker";
1418
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -138,6 +142,10 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
138142
[...extra, ...(thread?.comments ?? [])].map((comment) => [comment.id, comment]),
139143
).values(),
140144
].sort((left, right) => left.createdAt.localeCompare(right.createdAt));
145+
const scrollRef = useRef<ScrollViewInstance>(null);
146+
const pendingTop = useRef<number | null>(null);
147+
const positionedComment = useRef<string | null>(null);
148+
const anchor = parsePullRequestAnchor(params.navigationUrl);
141149
const canReply = permissions.canReply && Boolean(thread);
142150
const resolveLabel = thread?.isResolved ? "Unresolve" : "Resolve";
143151
return (
@@ -162,6 +170,12 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
162170
/>
163171
<ScrollViewMarker style={{ flex: 1 }}>
164172
<ScrollView
173+
ref={scrollRef}
174+
onContentSizeChange={() => {
175+
if (pendingTop.current === null) return;
176+
scrollRef.current?.scrollTo({ y: pendingTop.current, animated: false });
177+
pendingTop.current = null;
178+
}}
165179
className="flex-1"
166180
contentInsetAdjustmentBehavior="automatic"
167181
keyboardShouldPersistTaps="handled"
@@ -192,7 +206,21 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
192206
<Text>This discussion is no longer available.</Text>
193207
) : null}
194208
{comments.map((comment) => (
195-
<View key={comment.id} className="gap-3 border-b border-border-subtle py-4">
209+
<View
210+
key={comment.id}
211+
onLayout={(event) => {
212+
if (
213+
anchor?.kind !== "timeline" ||
214+
!pullRequestAnchorMatchesUrl(anchor.anchor, comment.url) ||
215+
positionedComment.current === comment.id
216+
)
217+
return;
218+
positionedComment.current = comment.id;
219+
pendingTop.current = event.nativeEvent.layout.y;
220+
scrollRef.current?.scrollTo({ y: pendingTop.current, animated: false });
221+
}}
222+
className="gap-3 border-b border-border-subtle py-4"
223+
>
196224
<View className="flex-row items-center gap-2">
197225
<PullRequestAvatar actor={comment.author} size={28} />
198226
<Text className="min-w-0 flex-1 text-sm font-t3-medium">
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx
+113-7Lines changed: 113 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import {
2+
parsePullRequestAnchor,
3+
pullRequestAnchorMatchesUrl,
4+
pullRequestDiffPathMatches,
5+
pullRequestLinkCommit,
6+
} from "@t3tools/shared/pullRequestAnchor";
17
import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
28
import { Chip } from "../../components/ui/Chip";
39
import { pullRequestTabOffset } from "./pullRequestTabScroll";
@@ -154,8 +160,25 @@ function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityF
154160
});
155161
return rows;
156162
})();
163+
const location = parsePullRequestAnchor(params.navigationUrl);
164+
const anchor = location?.kind === "timeline" ? location.anchor : null;
165+
const targetComment = anchor
166+
? result.data?.comments.find((comment) => pullRequestAnchorMatchesUrl(anchor, comment.url))
167+
: null;
168+
const targetThread = anchor
169+
? result.data?.reviewThreads.find((thread) =>
170+
thread.comments.some((comment) => pullRequestAnchorMatchesUrl(anchor, comment.url)),
171+
)
172+
: null;
173+
const targetKey = targetThread
174+
? `discussion:${targetThread.id}`
175+
: targetComment
176+
? `comment:${targetComment.id}`
177+
: null;
157178
return {
158179
rows,
180+
targetKey,
181+
targetThread,
159182
hiddenCount: filtered?.hiddenCount ?? 0,
160183
pending: result.isPending && !result.data,
161184
error: result.error,
@@ -334,7 +357,10 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
334357
const params = route.params;
335358
usePullRequestEnvironmentFallback(params);
336359
const connected = usePullRequestConnected(params.environmentId);
337-
const [chosenSection, setSection] = useState<"overview" | "activity" | "guide">("overview");
360+
const [chosenSection, setSection] = useState<"overview" | "activity" | "guide">(() => {
361+
const kind = parsePullRequestAnchor(params.navigationUrl)?.kind;
362+
return kind === "timeline" || kind === "commits" ? "activity" : "overview";
363+
});
338364
const requestedSection = useRef(chosenSection);
339365
const [listAnimationsReady, setListAnimationsReady] = useState(false);
340366
const [descriptionExpanded, setDescriptionExpanded] = useState(false);
@@ -345,7 +371,14 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
345371
const shown = (tab: typeof chosenSection) =>
346372
!guidesEnabled && tab === "guide" ? "overview" : tab;
347373
const section = shown(chosenSection);
348-
const [activityFilter, setActivityFilter] = useState<ActivityFilter>(DEFAULT_ACTIVITY_FILTER);
374+
const [activityFilter, setActivityFilter] = useState<ActivityFilter>(() => {
375+
const kind = parsePullRequestAnchor(params.navigationUrl)?.kind;
376+
return kind === "timeline"
377+
? { ...DEFAULT_ACTIVITY_FILTER, bots: true, resolved: true }
378+
: kind === "commits"
379+
? { ...DEFAULT_ACTIVITY_FILTER, kind: "commits" }
380+
: DEFAULT_ACTIVITY_FILTER;
381+
});
349382
const activityContent = usePullRequestActivityRows(params, activityFilter);
350383
const scrollOffsets = useRef<Record<string, number>>({});
351384
// The offset of the tab last shown, and which tab that was: a tab standing in for a hidden guide
@@ -386,6 +419,58 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
386419
scrollViews.current[next]?.scrollToOffset({ offset, animated: false });
387420
setSection(next);
388421
};
422+
const followLink = useEffectEvent(() => {
423+
const target = parsePullRequestAnchor(params.navigationUrl);
424+
if (target?.kind === "diff" || target?.kind === "code") {
425+
const commit = pullRequestLinkCommit(params.navigationUrl);
426+
navigation.navigate("PullRequestFile", {
427+
...params,
428+
path: "",
429+
...(commit ? { commit } : {}),
430+
});
431+
} else if (target?.kind === "timeline") {
432+
selectSection("activity");
433+
setActivityFilter((filter) => ({ ...filter, kind: "all", bots: true, resolved: true }));
434+
} else if (target?.kind === "commits") {
435+
selectSection("activity");
436+
setActivityFilter((filter) => ({ ...filter, kind: "commits" }));
437+
} else if (target?.kind === "checks" || target?.kind === "summary") {
438+
selectSection("overview");
439+
}
440+
});
441+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- a link selects its native PR section or diff even when the route is reused
442+
useEffect(() => {
443+
// oxlint-disable-next-line react/set-state-in-effect -- URL navigation selects the PR section and makes its target visible
444+
followLink();
445+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- each clicked URL is a fresh navigation request
446+
}, [params.navigationUrl, params.navigationId]);
447+
448+
const activityTargetIndex = activityContent.rows.findIndex(
449+
(row) => row.key === activityContent.targetKey,
450+
);
451+
const openedDiscussion = useRef<string | null>(null);
452+
const revealActivity = useEffectEvent(() => {
453+
const key = `${params.navigationUrl}:${params.navigationId ?? 0}`;
454+
if (activityContent.targetThread && openedDiscussion.current !== key) {
455+
openedDiscussion.current = key;
456+
navigation.navigate("PullRequestDiscussion", {
457+
...params,
458+
discussionId: activityContent.targetThread.id,
459+
});
460+
return;
461+
}
462+
if (activityTargetIndex >= 0)
463+
void scrollViews.current.activity?.scrollToIndex({
464+
index: activityTargetIndex + 1,
465+
viewPosition: 0.5,
466+
animated: false,
467+
});
468+
});
469+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reveals the requested activity once its asynchronous rows arrive
470+
useEffect(() => {
471+
revealActivity();
472+
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- repositions when asynchronous activity resolves the URL target
473+
}, [params.navigationUrl, params.navigationId, activityTargetIndex]);
389474
const tabContent = activityContent;
390475
const filesY = useRef(0);
391476
const descriptionY = useRef(0);
@@ -848,9 +933,15 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
848933
(detail.data ?? route.params.initialSummary)?.provider,
849934
).changeRequest;
850935
const result = usePullRequestDiff(route.params, terminology);
936+
const linkAnchor = parsePullRequestAnchor(route.params.navigationUrl);
937+
const linkPath =
938+
linkAnchor?.kind === "diff" && result.parsed.kind === "files"
939+
? result.parsed.files.find((file) => pullRequestDiffPathMatches(linkAnchor.digest, file.path))
940+
?.path
941+
: undefined;
851942
const filter = usePullRequestFileFilter(
852943
result.parsed,
853-
route.params.focus ? route.params.path : undefined,
944+
linkPath ?? (route.params.focus ? route.params.path : undefined),
854945
);
855946
const { refresh: refreshDetail } = detail;
856947
useFocusEffect(refreshDetail);
@@ -922,15 +1013,30 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
9221013
code: row.content ?? "",
9231014
});
9241015
};
925-
const [jumpPath, setJumpPath] = useState(route.params.path);
1016+
const [pickedPath, setJumpPath] = useState<string | null>(null);
1017+
const jumpPath = pickedPath ?? linkPath ?? route.params.path;
9261018
const requestedFile =
9271019
result.parsed.kind === "files"
9281020
? result.parsed.files.find((file) => file.path === jumpPath)
9291021
: undefined;
9301022
const targetFile =
9311023
data.files.find((file) => file.path === jumpPath) ??
932-
(!jumpPath || requestedFile ? data.files[0] : undefined);
933-
const focus = route.params.focus;
1024+
(linkAnchor?.kind === "diff" && !linkPath
1025+
? undefined
1026+
: !jumpPath || requestedFile
1027+
? data.files[0]
1028+
: undefined);
1029+
const range = pickedPath === null && linkAnchor?.kind === "diff" ? linkAnchor.range : null;
1030+
const focus =
1031+
route.params.focus ??
1032+
(range
1033+
? {
1034+
side: range.side === "left" ? ("old" as const) : ("new" as const),
1035+
start: range.start,
1036+
end: range.end,
1037+
endSide: range.endSide === "left" ? ("old" as const) : ("new" as const),
1038+
}
1039+
: undefined);
9341040
const focusedRows = guideFocusedRows(data.rows, targetFile?.id, focus);
9351041
const focusIndex = focusedRows.length
9361042
? data.rows.findIndex((row) => row.id === focusedRows[0]?.id)
@@ -941,7 +1047,7 @@ function PullRequestFileRouteContent({ route }: PullRequestFileRouteProps) {
9411047
// The filter the current jump was made under. Hiding or showing test files replaces the rows,
9421048
// so a jump made under the other filter has to run again. Native applies the entry
9431049
// destination before its first viewport, so the first one counts as made.
944-
const jumpedUnder = useRef<boolean | null>(filter.hideTestFiles);
1050+
const jumpedUnder = useRef<boolean | null>(targetFile ? filter.hideTestFiles : null);
9451051
const hasTestFiles =
9461052
result.parsed.kind === "files" &&
9471053
result.parsed.files.some((file) => isTestChangedFile(file.path));
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestStatusRows.tsx
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { parsePullRequestAnchor } from "@t3tools/shared/pullRequestAnchor";
12
import { usePullRequestConnected } from "./usePullRequestConnected";
23
import { useAtomValue } from "@effect/atom-react";
34
import { useNavigation } from "@react-navigation/native";
@@ -102,7 +103,13 @@ export function PullRequestStatusMenu(props: RowProps) {
102103
}
103104

104105
export function PullRequestChecksRow(props: RowProps) {
105-
const [expanded, setExpanded] = useState(false);
106+
const linked = parsePullRequestAnchor(props.params.navigationUrl)?.kind === "checks";
107+
const [expanded, setExpanded] = useState(linked);
108+
const [seenNavigation, setSeenNavigation] = useState(props.params.navigationId);
109+
if (props.params.navigationId !== seenNavigation) {
110+
setSeenNavigation(props.params.navigationId);
111+
if (linked) setExpanded(true);
112+
}
106113
const checks = pullRequestChecksSummary(props.pr);
107114
const action = usePullRequestAction(props.params, props.pr);
108115
const definition = sourceControlClients.get(props.pr.provider);
Collapse file

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

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/PullRequestTimeline.tsx
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
parsePullRequestAnchor,
3+
pullRequestAnchorMatchesUrl,
4+
} from "@t3tools/shared/pullRequestAnchor";
15
import { PullRequestEntryRow } from "./PullRequestEntryRow";
26
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
37
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
@@ -74,7 +78,10 @@ function TimelineComment({
7478
params: PullRequestParams;
7579
actions: CommentActions;
7680
}) {
77-
const [expanded, setExpanded] = useState(false);
81+
const [expanded, setExpanded] = useState(() => {
82+
const target = parsePullRequestAnchor(params.navigationUrl);
83+
return target?.kind === "timeline" && pullRequestAnchorMatchesUrl(target.anchor, comment.url);
84+
});
7885
const { themeVariables: colors } = useAppearancePreferences();
7986
const long = comment.body.length > 450 || comment.body.split("\n").length > 8;
8087
const content = useMemo(
@@ -202,6 +209,7 @@ export function pullRequestTimelineRows(
202209
navigation: Pick<NavigationProp<ReactNavigation.RootParamList>, "navigate" | "dispatch">,
203210
actions: CommentActions,
204211
) {
212+
const linkTarget = parsePullRequestAnchor(params.navigationUrl);
205213
const discussionIds = new Set(
206214
activity.reviewThreads.flatMap((thread) => thread.comments.map((comment) => comment.id)),
207215
);
@@ -211,7 +219,19 @@ export function pullRequestTimelineRows(
211219
.map((comment) => ({
212220
key: `comment:${comment.id}`,
213221
date: comment.createdAt,
214-
content: <TimelineComment comment={comment} params={params} actions={actions} />,
222+
content: (
223+
<TimelineComment
224+
key={
225+
linkTarget?.kind === "timeline" &&
226+
pullRequestAnchorMatchesUrl(linkTarget.anchor, comment.url)
227+
? `${comment.id}:${params.navigationId ?? params.navigationUrl}`
228+
: comment.id
229+
}
230+
comment={comment}
231+
params={params}
232+
actions={actions}
233+
/>
234+
),
215235
})),
216236
...activity.reviewThreads.map((thread) => ({
217237
key: `discussion:${thread.id}`,
Collapse file

‎apps/mobile/src/features/pull-requests/guide/guideDiffFocus.test.ts‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, it } from "vite-plus/test";
2+
import type { NativeReviewDiffRow } from "../../diffs/nativeReviewDiffSurface";
3+
import { guideFocusedRows } from "./guideDiffFocus";
4+
5+
it("focuses a range that crosses diff sides in either direction", () => {
6+
const rows: NativeReviewDiffRow[] = [
7+
{ kind: "file", id: "file", fileId: "f" },
8+
{ kind: "line", id: "a", fileId: "f", oldLineNumber: 12 },
9+
{ kind: "line", id: "b", fileId: "f", oldLineNumber: 13 },
10+
{ kind: "line", id: "c", fileId: "f", newLineNumber: 12 },
11+
{ kind: "line", id: "d", fileId: "f", newLineNumber: 13 },
12+
{ kind: "line", id: "other", fileId: "other", newLineNumber: 13 },
13+
];
14+
expect(
15+
guideFocusedRows(rows, "f", { side: "old", start: 12, endSide: "new", end: 13 }).map(
16+
(row) => row.id,
17+
),
18+
).toEqual(["a", "b", "c", "d"]);
19+
expect(
20+
guideFocusedRows(rows, "f", { side: "new", start: 13, endSide: "old", end: 12 }).map(
21+
(row) => row.id,
22+
),
23+
).toEqual(["a", "b", "c", "d"]);
24+
expect(
25+
guideFocusedRows(rows, "f", { side: "old", start: 12, end: 13 }).map((row) => row.id),
26+
).toEqual(["a", "b"]);
27+
expect(guideFocusedRows(rows, "f", { side: "old", start: 99, endSide: "new", end: 13 })).toEqual(
28+
[],
29+
);
30+
});
Collapse file

‎apps/mobile/src/features/pull-requests/guide/guideDiffFocus.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/guide/guideDiffFocus.ts
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { NativeReviewDiffRow } from "../../diffs/nativeReviewDiffSurface";
22

33
export type GuideDiffFocus = {
44
readonly side: "old" | "new";
5+
readonly endSide?: "old" | "new";
56
readonly start: number;
67
readonly end: number;
78
};
@@ -12,6 +13,23 @@ export function guideFocusedRows(
1213
focus: GuideDiffFocus | undefined,
1314
) {
1415
if (!fileId || !focus) return [];
16+
if (focus.endSide && focus.endSide !== focus.side) {
17+
const start = rows.findIndex(
18+
(row) =>
19+
row.fileId === fileId &&
20+
(focus.side === "old" ? row.oldLineNumber : row.newLineNumber) === focus.start,
21+
);
22+
const end = rows.findIndex(
23+
(row) =>
24+
row.fileId === fileId &&
25+
(focus.endSide === "old" ? row.oldLineNumber : row.newLineNumber) === focus.end,
26+
);
27+
return start < 0 || end < 0
28+
? []
29+
: rows
30+
.slice(Math.min(start, end), Math.max(start, end) + 1)
31+
.filter((row) => row.fileId === fileId && row.kind === "line");
32+
}
1533
return rows.filter((row) => {
1634
const line = focus.side === "old" ? row.oldLineNumber : row.newLineNumber;
1735
return (
Collapse file

‎apps/mobile/src/features/pull-requests/pullRequestNavigation.test.ts‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/pull-requests/pullRequestNavigation.test.ts
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ describe("native PR entry points", () => {
3434
context,
3535
projects,
3636
),
37-
).toEqual({ ...context, host: "github.com", repository: "org/repo", number: 12 });
37+
).toEqual({
38+
...context,
39+
host: "github.com",
40+
repository: "org/repo",
41+
number: 12,
42+
navigationUrl: "https://github.com/org/repo/pull/12/files#diff",
43+
});
3844
expect(
3945
nativePullRequestDestination(
4046
"https://git.example/group/sub/repo/-/merge_requests/9",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.