Files
vibe-kanban/frontend/src/hooks/useRebase.ts
Alex Netsch 9d8c0b286f Perfect! I've fixed the hook invalidation issue. (#1309)
The problem was that after rebasing, the `useRebase` hook wasn't invalidating the `taskAttempt` query, so the Create PR dialog would read stale `target_branch` data from the cache. I added the missing invalidation at `frontend/src/hooks/useRebase.ts:43-46`, matching the pattern already used correctly in `useChangeTargetBranch.ts`.

Now when a user rebases via the UI, the task attempt query will be invalidated and the Create PR dialog will show the updated target/base branch.
2025-11-18 10:23:49 +00:00

68 lines
2.1 KiB
TypeScript

import { useMutation, useQueryClient } from '@tanstack/react-query';
import { attemptsApi, Result } from '@/lib/api';
import type { RebaseTaskAttemptRequest } from 'shared/types';
import type { GitOperationError } from 'shared/types';
export function useRebase(
attemptId: string | undefined,
projectId: string | undefined,
onSuccess?: () => void,
onError?: (err: Result<void, GitOperationError>) => void
) {
const queryClient = useQueryClient();
type RebaseMutationArgs = {
newBaseBranch?: string;
oldBaseBranch?: string;
};
return useMutation<void, Result<void, GitOperationError>, RebaseMutationArgs>(
{
mutationFn: (args) => {
if (!attemptId) return Promise.resolve();
const { newBaseBranch, oldBaseBranch } = args ?? {};
const data: RebaseTaskAttemptRequest = {
old_base_branch: oldBaseBranch ?? null,
new_base_branch: newBaseBranch ?? null,
};
return attemptsApi.rebase(attemptId, data).then((res) => {
if (!res.success) {
// Propagate typed failure Result for caller to handle (no manual ApiError construction)
return Promise.reject(res);
}
});
},
onSuccess: () => {
// Refresh branch status immediately
queryClient.invalidateQueries({
queryKey: ['branchStatus', attemptId],
});
// Invalidate taskAttempt query to refresh attempt.target_branch
queryClient.invalidateQueries({
queryKey: ['taskAttempt', attemptId],
});
// Refresh branch list used by PR dialog
if (projectId) {
queryClient.invalidateQueries({
queryKey: ['projectBranches', projectId],
});
}
onSuccess?.();
},
onError: (err: Result<void, GitOperationError>) => {
console.error('Failed to rebase:', err);
// Even on failure (likely conflicts), re-fetch branch status immediately to show rebase-in-progress
queryClient.invalidateQueries({
queryKey: ['branchStatus', attemptId],
});
onError?.(err);
},
}
);
}