Skip to content

Commit bd8c34c

Browse files
committed
fix(web): retain automatic diff reads and show empty comparisons
1 parent 4d14740 commit bd8c34c

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎apps/web/src/components/DiffPanel.browser.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ function preview(): ReviewDiffPreviewResult {
101101
diff: "",
102102
diffHash: "empty",
103103
truncated: false,
104+
patchesDeferred: true,
105+
files: [],
104106
},
105107
],
106108
};

‎apps/web/src/components/DiffPanel.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ export default function DiffPanel({
484484
: selectedTurn
485485
? activeCheckpointDiff
486486
: branchDiffPreview;
487-
const isLoadingSelectedPatch = selectedPatchQuery.isPending && selectedPatchQuery.data === null;
487+
const isLoadingSelectedPatch =
488+
selectedPatchQuery.isPending &&
489+
(selectedPatchQuery.data === null ||
490+
(isGitSelection && preview?.incomplete === true && selectedGitSource?.files?.length === 0));
488491
const selectedPatchError = toolCallSelection
489492
? toolCallDetail.error
490493
: selectedTurn
@@ -499,7 +502,7 @@ export default function DiffPanel({
499502
const lazySource =
500503
isGitSelection &&
501504
(selectedGitSource?.truncated || selectedGitSource?.patchesDeferred) &&
502-
selectedGitSource.files
505+
selectedGitSource.files?.length
503506
? selectedGitSource
504507
: null;
505508
const renderablePatch = getRenderablePatch(

‎apps/web/src/components/diffs/useReviewFilePatches.browser.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function Probe({ source }: { source: ReviewDiffPreviewSource }) {
6969
);
7070
}
7171

72-
it("retains an opened later file through metadata insertion, refresh failure and retry", async () => {
72+
it("retains automatic and explicitly opened files through metadata insertion, refresh failure and retry", async () => {
7373
state.patches.clear();
7474
const registry = AtomRegistry.make();
7575
using _registry = { [Symbol.dispose]: () => registry.dispose() };
@@ -89,9 +89,22 @@ it("retains an opened later file through metadata insertion, refresh failure and
8989
});
9090
act(() => registry.set(atom, loaded));
9191
await expect.element(screen.getByText("f.txt:loaded")).toBeVisible();
92+
const automatic = [...state.patches].find(([key]) => JSON.parse(key)[1] === "e.txt")![1];
93+
act(() =>
94+
registry.set(
95+
automatic,
96+
AsyncResult.success({
97+
...loaded.value,
98+
diff: loaded.value.diff.replaceAll("f.txt", "e.txt"),
99+
files: tracked.files!.filter((file) => file.path === "e.txt"),
100+
}),
101+
),
102+
);
103+
await expect.element(screen.getByText("e.txt:loaded")).toBeVisible();
92104
await screen.rerender(
93105
view(source(["a-new.txt", ...tracked.files!.map((f) => f.path)], "complete")),
94106
);
107+
await expect.element(screen.getByText("e.txt:loaded")).toBeVisible();
95108
await expect.element(screen.getByText("f.txt:loaded")).toBeVisible();
96109
act(() =>
97110
registry.set(

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ export function useReviewFilePatches({
4949
baseRef,
5050
ignoreWhitespace,
5151
]);
52-
const [requested, setRequested] = useState(() => ({ scope, paths: [] as string[] }));
52+
const files = sortedReviewFiles(source);
53+
const automaticPaths = files.slice(0, INITIAL_FILE_COUNT).map((file) => file.path);
54+
const [requested, setRequested] = useState(() => ({ scope, paths: automaticPaths }));
55+
const previousPaths = requested.scope === scope ? requested.paths : [];
56+
const paths = [...new Set([...previousPaths, ...automaticPaths])];
57+
if (requested.scope !== scope || paths.length !== previousPaths.length) {
58+
setRequested({ scope, paths });
59+
}
5360
const queries = reviewFileQueries({
5461
environmentId,
5562
cwd,
@@ -69,7 +76,6 @@ export function useReviewFilePatches({
6976
const query = queries.find(({ index }) => files[index]?.path === path)?.query;
7077
if (query) registry.refresh(query);
7178
});
72-
const files = sortedReviewFiles(source);
7379
const pendingIndex = files.findIndex((_, index) => {
7480
const patch = patches.get(index);
7581
return !patch || patch._tag === "Initial";

0 commit comments

Comments
 (0)