Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions apps/web/src/components/pullRequest/PullRequestCodeTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
toViewerSide,
} from "./PullRequestReviewAnnotation";
import {
getFileViewedRange,
isFileDiffCollapsed,
isLineInFileDiff,
toggleFileDiffFoldForViewed,
Expand Down Expand Up @@ -175,7 +176,7 @@ interface FileViewedToggleState {
readonly enabled: boolean;
readonly isViewed: (path: string) => boolean;
readonly isStale: (path: string) => boolean;
readonly setFileViewed: (fileKey: string, path: string, viewed: boolean) => void;
readonly setFileViewed: (fileKey: string, viewed: boolean, extendRange: boolean) => void;
}

// Context updates viewed toggles without invalidating memoized header portals.
Expand Down Expand Up @@ -205,7 +206,13 @@ function FileViewedToggle({
<Checkbox
aria-label={stale ? "Changed" : "Viewed"}
checked={viewed}
onCheckedChange={(next) => viewedFiles.setFileViewed(fileKey, path, next === true)}
onCheckedChange={(next, details) =>
viewedFiles.setFileViewed(
fileKey,
next === true,
"shiftKey" in details.event && details.event.shiftKey === true,
)
}
/>
{stale ? (
<Tooltip>
Expand Down Expand Up @@ -287,6 +294,7 @@ function PullRequestCodeTab({
wordWrap: settings.wordWrap,
}));
const [toggledFiles, setToggledFiles] = useState<ReadonlySet<string>>(() => new Set());
const [lastViewedFileKey, setLastViewedFileKey] = useState<string | null>(null);
const [visibleCommitCount, setVisibleCommitCount] = useState(COMMIT_PAGE_SIZE);
const [foldOverride, setFoldOverride] = useState<DiffFoldOverride>(null);
const effectiveFoldOverride =
Expand Down Expand Up @@ -326,6 +334,7 @@ function PullRequestCodeTab({
const [stateScopeKey, setStateScopeKey] = useState(scopeKey);
if (stateScopeKey !== scopeKey) {
setStateScopeKey(scopeKey);
setLastViewedFileKey(null);
setDraft(null);
setSelectedLines(null);
setToggledFiles(new Set());
Expand Down Expand Up @@ -689,10 +698,20 @@ function PullRequestCodeTab({
return next;
});

const setFileViewed = (fileKey: string, path: string, viewed: boolean) => {
setViewed(path, viewed);
const setFileViewed = (fileKey: string, viewed: boolean, extendRange: boolean) => {
const range = getFileViewedRange(
annotatedFiles,
fileKey,
extendRange ? lastViewedFileKey : null,
);
setLastViewedFileKey(fileKey);
for (const file of range) setViewed(file.path, viewed);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High pullRequest/PullRequestCodeTab.tsx:708

Shift-clicking a range of more than 500 files queues every path, so the flush sends a setFilesViewed request that exceeds PullRequestSetFilesViewedInput’s 500-file limit; the viewed marks are not persisted even though the handler folds the files. Split queued paths into batches of at most 500 in filesViewedStore.ts, including paths queued by earlier presses.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/web/src/components/pullRequest/PullRequestCodeTab.tsx around line 708:

Shift-clicking a range of more than 500 files queues every path, so the flush sends a `setFilesViewed` request that exceeds `PullRequestSetFilesViewedInput`’s 500-file limit; the viewed marks are not persisted even though the handler folds the files. Split queued paths into batches of at most 500 in `filesViewedStore.ts`, including paths queued by earlier presses.

setToggledFiles((current) =>
toggleFileDiffFoldForViewed(fileKey, viewed, effectiveFoldOverride, current),
range.reduce(
(next, file) =>
toggleFileDiffFoldForViewed(file.fileKey, viewed, effectiveFoldOverride, next),
current,
),
);
};
const fileViewedToggle = {
Expand Down
17 changes: 17 additions & 0 deletions apps/web/src/components/pullRequest/pullRequestDiff.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { FileDiffMetadata } from "@pierre/diffs";
import { describe, expect, it } from "vite-plus/test";

import {
getFileViewedRange,
isFileDiffCollapsed,
isLineInFileDiff,
toggleFileDiffFoldForViewed,
Expand Down Expand Up @@ -54,3 +55,19 @@ describe("toggleFileDiffFoldForViewed", () => {
expect(toggleFileDiffFoldForViewed("a.ts", false, "expanded", new Set()).size).toBe(0);
});
});

describe("getFileViewedRange", () => {
const files = ["c.ts", "a.ts", "b.ts", "d.ts"].map((fileKey) => ({ fileKey }));

it("includes both endpoints in displayed order in either direction", () => {
expect(getFileViewedRange(files, "b.ts", "c.ts")).toEqual(files.slice(0, 3));
expect(getFileViewedRange(files, "c.ts", "b.ts")).toEqual(files.slice(0, 3));
expect(getFileViewedRange(files, "a.ts", "a.ts")).toEqual([files[1]]);
});

it("changes only the clicked file without a current anchor", () => {
expect(getFileViewedRange(files, "a.ts", null)).toEqual([files[1]]);
expect(getFileViewedRange(files, "a.ts", "removed.ts")).toEqual([files[1]]);
expect(getFileViewedRange(files, "removed.ts", "a.ts")).toEqual([]);
});
});
12 changes: 12 additions & 0 deletions apps/web/src/components/pullRequest/pullRequestDiff.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ export function toggleFileDiffFoldForViewed(
else next.add(fileKey);
return next;
}

export function getFileViewedRange<T extends { readonly fileKey: string }>(
files: ReadonlyArray<T>,
fileKey: string,
anchorFileKey: string | null,
): ReadonlyArray<T> {
const index = files.findIndex((file) => file.fileKey === fileKey);
if (index === -1) return [];
const anchorIndex = files.findIndex((file) => file.fileKey === anchorFileKey);
if (anchorIndex === -1) return files.slice(index, index + 1);
return files.slice(Math.min(index, anchorIndex), Math.max(index, anchorIndex) + 1);
}
Loading