Skip to content

Commit df232a1

Browse files
fix(web): any known comment fragment rereads the host, not only kinds already loaded
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f52b391 commit df232a1

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ describe("review thread conversations", () => {
589589
expect(pullRequestCommentLinkMayLoad(issueItems, `${pull}#issuecomment-999`)).toBe(true);
590590
expect(pullRequestCommentLinkMayLoad(githubItems, `${pull}/files#r999`)).toBe(true);
591591
expect(pullRequestCommentLinkMayLoad([], `${pull}#issuecomment-1`)).toBe(true);
592+
for (const fragment of ["#discussion_r42", "/files#r42", "#pullrequestreview-42"]) {
593+
expect(pullRequestCommentLinkMayLoad(issueItems, `${pull}${fragment}`), fragment).toBe(true);
594+
}
592595
for (const fragment of ["#diff-abc", "#issue-1", "#event-1", "#partial-pull-merging", ""]) {
593596
expect(pullRequestCommentLinkMayLoad(issueItems, `${pull}/files${fragment}`), fragment).toBe(
594597
false,

‎apps/web/src/components/pullRequest/pullRequestDetail.logic.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,26 +658,35 @@ function anchorKind(anchor: string) {
658658
return anchor.slice(0, end);
659659
}
660660

661+
// GitHub, GitLab, Forgejo and Bitbucket comment fragments; a newer comment may be the first of its kind.
662+
const COMMENT_ANCHOR_KINDS = [
663+
"#issuecomment-",
664+
"#discussion_r",
665+
"#pullrequestreview-",
666+
"#note_",
667+
"#comment-",
668+
];
669+
661670
/**
662671
* Whether a link no loaded comment matches could name a newer one: its fragment is shaped like a
663-
* loaded comment's, so `#diff-…` or `#event-…` never asks the host again.
672+
* comment's, so `#diff-…` or `#event-…` never asks the host again.
664673
*/
665674
export function pullRequestCommentLinkMayLoad(
666675
items: ReadonlyArray<PullRequestConversationItem>,
667676
url: string,
668677
): boolean {
669678
const anchor = commentAnchor(url);
670679
if (!anchor) return false;
671-
const kinds = new Set(
672-
items.flatMap((item) =>
680+
const kinds = new Set([
681+
...COMMENT_ANCHOR_KINDS,
682+
...items.flatMap((item) =>
673683
pullRequestConversationItemComments(item).flatMap((comment) => {
674684
const loaded = comment.url === null ? null : commentAnchor(comment.url);
675685
return loaded ? [anchorKind(loaded)] : [];
676686
}),
677687
),
678-
);
679-
// With no loaded anchor to compare, the link may name the first comment.
680-
return kinds.size === 0 || kinds.has(anchorKind(anchor));
688+
]);
689+
return kinds.has(anchorKind(anchor));
681690
}
682691

683692
export function filterPullRequestConversationItems(

0 commit comments

Comments
 (0)