Skip to content
Draft
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
14 changes: 14 additions & 0 deletions packages/ui/src/features/sidebar/useTaskPrStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,18 @@ describe("useTaskPrStatus", () => {
);
expect(lastQueryOptions?.enabled).toBe(true);
});

it("ignores leftover placeholder data from a previous task when the query is disabled", () => {
// Simulates switching from a cloud task with a PR (query data populated)
// to a fresh cloud task with no PR yet — TanStack's `placeholderData`
// would otherwise keep serving the previous task's resolved data since
// the disabled query never fetches to overwrite it.
queryData = { prState: "open", hasDiff: true };
const { result } = renderHook(() =>
useTaskPrStatus(
makeTask({ taskRunEnvironment: "cloud", cloudPrUrl: null }),
),
);
expect(result.current).toEqual({ prState: null, hasDiff: false });
});
});
7 changes: 6 additions & 1 deletion packages/ui/src/features/sidebar/useTaskPrStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export function useTaskPrStatus(task: {
),
);

if (!data || (!data.prState && !data.hasDiff)) return EMPTY;
// When the query is disabled, `data` can still be populated:
// `placeholderData: (prev) => prev` carries over whatever the previous
// task's query resolved to, and a disabled query never fetches to replace
// it. Without this guard, switching from a task with a PR to one without
// (e.g. a fresh cloud task) would keep showing the old task's PR status.
if (skipQuery || !data || (!data.prState && !data.hasDiff)) return EMPTY;
return data;
}
Loading