refactor(checkout-diff): rely solely on subscription for data

Drop the one-shot getCheckoutDiff query and use skipToken; the
subscribe_checkout_diff flow populates the cache on subscribe response
and updates. Derive isLoading from the presence of cached payload and
remove the now-unused isError/error fields from git-diff-pane.
This commit is contained in:
Mohamed Boudra
2026-04-20 10:45:59 +07:00
parent 67eddbd6a9
commit 53baa16bee
2 changed files with 8 additions and 29 deletions
@@ -681,8 +681,6 @@ export function GitDiffPane({ serverId, workspaceId, cwd, hideHeaderRow }: GitDi
files, files,
payloadError: diffPayloadError, payloadError: diffPayloadError,
isLoading: isDiffLoading, isLoading: isDiffLoading,
isError: isDiffError,
error: diffError,
} = useCheckoutDiffQuery({ } = useCheckoutDiffQuery({
serverId, serverId,
cwd, cwd,
@@ -1071,9 +1069,7 @@ export function GitDiffPane({ serverId, workspaceId, cwd, hideHeaderRow }: GitDi
); );
const hasChanges = files.length > 0; const hasChanges = files.length > 0;
const diffErrorMessage = const diffErrorMessage = diffPayloadError?.message ?? null;
diffPayloadError?.message ??
(isDiffError && diffError instanceof Error ? diffError.message : null);
const prErrorMessage = githubFeaturesEnabled ? (prPayloadError?.message ?? null) : null; const prErrorMessage = githubFeaturesEnabled ? (prPayloadError?.message ?? null) : null;
const branchLabel = const branchLabel =
gitStatus?.currentBranch && gitStatus.currentBranch !== "HEAD" gitStatus?.currentBranch && gitStatus.currentBranch !== "HEAD"
@@ -1,4 +1,4 @@
import { useQuery, useQueryClient } from "@tanstack/react-query"; import { skipToken, useQuery, useQueryClient } from "@tanstack/react-query";
import { useEffect, useId, useMemo } from "react"; import { useEffect, useId, useMemo } from "react";
import { useIsCompactFormFactor } from "@/constants/layout"; import { useIsCompactFormFactor } from "@/constants/layout";
import { usePanelStore } from "@/stores/panel-store"; import { usePanelStore } from "@/stores/panel-store";
@@ -76,27 +76,10 @@ export function useCheckoutDiffQuery({
[serverId, cwd, mode, baseRef, compareIgnoreWhitespace], [serverId, cwd, mode, baseRef, compareIgnoreWhitespace],
); );
const query = useQuery({ const query = useQuery<CheckoutDiffQueryPayload>({
queryKey, queryKey,
queryFn: async () => { queryFn: skipToken,
if (!client) {
throw new Error("Daemon client not available");
}
const payload = await client.getCheckoutDiff(cwd, {
mode: compareMode,
baseRef: compareBaseRef,
ignoreWhitespace: compareIgnoreWhitespace,
});
return {
...payload,
files: orderCheckoutDiffFiles(payload.files),
};
},
enabled: !!client && isConnected && !!cwd && enabled,
staleTime: Infinity, staleTime: Infinity,
refetchOnMount: false,
refetchOnReconnect: false,
refetchOnWindowFocus: false,
}); });
useEffect(() => { useEffect(() => {
@@ -208,9 +191,9 @@ export function useCheckoutDiffQuery({
return { return {
files: payload?.files ?? [], files: payload?.files ?? [],
payloadError, payloadError,
isLoading: query.isLoading, isLoading: payload === null && enabled && isConnected,
isFetching: query.isFetching, isFetching: false,
isError: query.isError || Boolean(payloadError), isError: Boolean(payloadError),
error: query.error, error: null,
}; };
} }