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
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@
},
"devDependencies": {
"@fontsource-variable/geist": "^5.3.0",
"@pierre/diffs": "1.3.1",
"@pierre/diffs": "1.3.6",
"@pierre/trees": "1.0.0-beta.6",
"@radix-ui/react-icons": "^1.3.2",
"@types/node": "^24.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.3.4",
"oxfmt": "^0.60.0",
"oxlint": "^1.75.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@types/react": "^19.2.18",
"@types/react-dom": "^19.2.5",
"@vitejs/plugin-react": "^5.2.0",
"oxfmt": "^0.65.0",
"oxlint": "^1.80.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"typescript": "^5.7.0",
"vite": "^7.3.5",
"vitest": "^3.2.6"
Expand Down
422 changes: 225 additions & 197 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

36 changes: 21 additions & 15 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export function App() {
useEffect(() => {
if (!sessionReady || filter === null) return;
let opened = false;
// This effect owns the SSE subscription and its status.
// oxlint-disable-next-line react/set-state-in-effect
setConnection('connecting');
patchHashRef.current = null;
void loadPatch(filter);
Expand All @@ -165,11 +167,6 @@ export function App() {
});
}, [sessionReady, filter, loadPatch]);

useEffect(() => {
setDraft(null);
setSelectedLines(null);
}, [activeFilter]);

const { files: parsedFiles, clearCache: clearParsedFileCache } = usePatchModel(patch);
const filterComments = useMemo(
() => comments.filter((comment) => comment.filter === activeFilter),
Expand Down Expand Up @@ -263,6 +260,8 @@ export function App() {
);

const versionsRef = useRef(new Map<string, { version: number; key: string }>());
// CodeView re-reads an item only when its version changes.
/* oxlint-disable react/refs, react/memo-dependencies */
const items = useMemo<CodeViewItem<AnnotationMeta>[]>(
() =>
displayedParsedFiles.map(({ path, fileDiff, sectionHash }) => {
Expand Down Expand Up @@ -300,12 +299,15 @@ export function App() {
filesByPath,
],
);
/* oxlint-enable react/refs, react/memo-dependencies */

const captureScrollAnchor = useScrollAnchor(viewerRef, items, patch?.patchHash ?? '');
prepareForRefreshRef.current = () => {
captureScrollAnchor(true);
clearParsedFileCache();
};
useEffect(() => {
prepareForRefreshRef.current = () => {
captureScrollAnchor(true);
clearParsedFileCache();
};
});

useEffect(() => {
const target = pendingHashTargetRef.current;
Expand Down Expand Up @@ -352,12 +354,16 @@ export function App() {

const changeFilter = useStableCallback((next: DiffFilter) => {
if (edits.pendingAction) return;
if (
next !== activeFilter &&
edits.dirtyPaths.size > 0 &&
!window.confirm('Discard unsaved file changes and switch diff source?')
) {
return;
if (next !== activeFilter) {
if (
edits.dirtyPaths.size > 0 &&
!window.confirm('Discard unsaved file changes and switch diff source?')
) {
return;
}
setDraft(null);
setSelectedLines(null);
edits.reset();
}
setFilter(next);
});
Expand Down
9 changes: 8 additions & 1 deletion ui/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ function FilesTree({
const stablePaths = useStablePaths(sortedPaths);
const preparedInput = useMemo(() => preparePresortedFileTreeInput(stablePaths), [stablePaths]);

// Latest data for callbacks captured once at model creation.
// useFileTree captures these callbacks once, so they read current data from refs.
/* oxlint-disable react/refs */
const filePathsRef = useRef(new Set<string>());
const commentCountsRef = useRef(new Map<string, number>());
const dirtyPathsRef = useRef(dirtyPaths);
dirtyPathsRef.current = dirtyPaths;
filePathsRef.current = new Set(files.map((f) => f.path));
commentCountsRef.current = countByPath(comments);
/* oxlint-enable react/refs */

const handleSelectionChange = useStableCallback((selected: readonly string[]) => {
const path = selected[0];
Expand Down Expand Up @@ -209,6 +211,8 @@ function FilesTree({
useEffect(() => {
// Re-render decorations with the latest value from commentCountsRef.
model.setComposition();
// Both values trigger updates to the ref-backed decorations.
// oxlint-disable-next-line react/exhaustive-effect-dependencies
}, [model, comments, dirtyPaths]);

if (files.length === 0) {
Expand Down Expand Up @@ -368,6 +372,8 @@ function groupByFile(comments: ReviewComment[], files: PatchFileSummary[]): Comm
return ordered;
}

// Keep the array identity when its contents have not changed.
/* oxlint-disable react/refs */
function useStablePaths(paths: readonly string[]): readonly string[] {
const stable = useRef(paths);
if (
Expand All @@ -378,6 +384,7 @@ function useStablePaths(paths: readonly string[]): readonly string[] {
}
return stable.current;
}
/* oxlint-enable react/refs */

function countByPath(comments: ReviewComment[]): Map<string, number> {
const counts = new Map<string, number>();
Expand Down
7 changes: 4 additions & 3 deletions ui/src/useEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export function useEdits({

useEffect(() => {
if (!hasEditableFiles || editorReady) return;
// The effect owns the loading state for this import.
// oxlint-disable-next-line react/set-state-in-effect
setLoadingCount((count) => count + 1);
void loadEditModule()
.then(() => setEditorReady(true))
Expand All @@ -132,8 +134,6 @@ export function useEdits({
setError(null);
});

useEffect(() => reset(), [activeFilter, reset]);

const fetchContents = useStableCallback(
(fileDiff: FileDiffMetadata, path: string): Promise<FileContentsPayload> => {
let request = requestsRef.current.get(fileDiff);
Expand Down Expand Up @@ -184,7 +184,7 @@ export function useEdits({
}
});

const updateEdit = useStableCallback((path: string, change: PendingChange) => {
const updateEdit = useStableCallback(function updateEdit(path: string, change: PendingChange) {
if (change.item.type !== 'diff' || actionPendingRef.current) return;
const { fileDiff } = change.item;
const previous = editsRef.current.get(path);
Expand Down Expand Up @@ -319,6 +319,7 @@ export function useEdits({
return {
edits,
dirtyPaths,
reset,
pendingAction,
error,
loading: loadingCount > 0,
Expand Down
3 changes: 3 additions & 0 deletions ui/src/usePatchModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function usePatchModel(patch: PatchPayload | null) {
const cacheRef = useRef(new Map<string, FileDiffMetadata>());
const clearCache = useCallback(() => cacheRef.current.clear(), []);

// Reuse parsed metadata for unchanged sections across patch refreshes.
/* oxlint-disable react/refs */
const files = useMemo<ParsedFile[]>(() => {
if (!patch || patch.patch === '') return [];

Expand All @@ -39,6 +41,7 @@ export function usePatchModel(patch: PatchPayload | null) {
cacheRef.current = next;
return parsed;
}, [patch]);
/* oxlint-enable react/refs */

return { files, clearCache };
}
3 changes: 3 additions & 0 deletions ui/src/useScrollAnchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export function useScrollAnchor<T>(
if (!anchor.waitForPatch || patchArrived) anchorRef.current = null;
});
return () => cancelAnimationFrame(frame);
// Items trigger restoration after the list changes. restore is stable but
// still required by react-hooks/exhaustive-deps.
// oxlint-disable-next-line react/exhaustive-effect-dependencies
}, [items, patchHash, restore]);

useEffect(() => {
Expand Down