From 59c5f29e252d0551384ab9638bbcf2ffdea5c26d Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Fri, 27 Mar 2026 12:35:24 -0700 Subject: [PATCH] fix: force-refresh PR status and checks when manually refreshing (#141) The refresh button was serving cached data instead of fetching fresh PR status and checks. Added force option to bypass cache TTL on manual refresh, and ensured checks are fetched for the correct (refreshed) PR number. Co-authored-by: Claude Opus 4.6 --- .../components/right-sidebar/ChecksPanel.tsx | 77 ++++++++++++------- src/renderer/src/store/slices/github.ts | 25 ++++-- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx index 758c912d3..355f68f84 100644 --- a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx +++ b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx @@ -29,6 +29,7 @@ export default function ChecksPanel(): React.JSX.Element { const [checks, setChecks] = useState([]) const [checksLoading, setChecksLoading] = useState(false) const [emptyRefreshing, setEmptyRefreshing] = useState(false) + const [isRefreshing, setIsRefreshing] = useState(false) const [editingTitle, setEditingTitle] = useState(false) const [titleDraft, setTitleDraft] = useState('') const [titleSaving, setTitleSaving] = useState(false) @@ -65,30 +66,39 @@ export default function ChecksPanel(): React.JSX.Element { }, [repo, branch, fetchPRForBranch]) // Fetch checks via cached store method - const fetchChecks = useCallback(async () => { - if (!repo || !prNumber) { - return - } - setChecksLoading(true) - try { - const result = await fetchPRChecks(repo.path, prNumber, branch) - setChecks(result) + const fetchChecks = useCallback( + async ({ + force = false, + prNumberOverride + }: { force?: boolean; prNumberOverride?: number | null } = {}) => { + const targetPRNumber = prNumberOverride ?? prNumber + if (!repo || !targetPRNumber) { + return + } + setChecksLoading(true) + try { + const result = await fetchPRChecks(repo.path, targetPRNumber, branch, { force }) + setChecks(result) - // Exponential backoff: if checks haven't changed, double the interval (cap 120s). - // If they changed, reset to 30s. - const signature = JSON.stringify(result.map((c) => `${c.name}:${c.status}:${c.conclusion}`)) - pollIntervalRef.current = - signature === prevChecksRef.current - ? Math.min(pollIntervalRef.current * 2, 120_000) - : 30_000 - prevChecksRef.current = signature - } catch (err) { - console.warn('Failed to fetch PR checks:', err) - setChecks([]) - } finally { - setChecksLoading(false) - } - }, [repo, prNumber, branch, fetchPRChecks]) + // Exponential backoff: if checks haven't changed, double the interval (cap 120s). + // If they changed, reset to 30s. + const signature = JSON.stringify( + result.map((c) => `${c.name}:${c.status}:${c.conclusion}`) + ) + pollIntervalRef.current = + signature === prevChecksRef.current + ? Math.min(pollIntervalRef.current * 2, 120_000) + : 30_000 + prevChecksRef.current = signature + } catch (err) { + console.warn('Failed to fetch PR checks:', err) + setChecks([]) + } finally { + setChecksLoading(false) + } + }, + [repo, prNumber, branch, fetchPRChecks] + ) // Fetch checks on mount + poll with exponential backoff useEffect(() => { @@ -126,9 +136,17 @@ export default function ChecksPanel(): React.JSX.Element { if (!repo || !branch) { return } - // Refresh PR data + checks - await fetchPRForBranch(repo.path, branch) - await fetchChecks() + setIsRefreshing(true) + try { + const refreshedPR = await fetchPRForBranch(repo.path, branch, { force: true }) + if (refreshedPR) { + await fetchChecks({ force: true, prNumberOverride: refreshedPR.number }) + } else { + setChecks([]) + } + } finally { + setIsRefreshing(false) + } }, [repo, branch, fetchPRForBranch, fetchChecks]) const handleStartEdit = useCallback(() => { @@ -159,7 +177,7 @@ export default function ChecksPanel(): React.JSX.Element { }) if (ok) { // Re-fetch PR to get updated title - await fetchPRForBranch(repo.path, branch) + await fetchPRForBranch(repo.path, branch, { force: true }) } } finally { setTitleSaving(false) @@ -182,7 +200,7 @@ export default function ChecksPanel(): React.JSX.Element { // Refresh PR (passed to PRActions) const handleRefreshPR = useCallback(async () => { if (repo && branch) { - await fetchPRForBranch(repo.path, branch) + await fetchPRForBranch(repo.path, branch, { force: true }) } }, [repo, branch, fetchPRForBranch]) @@ -275,8 +293,9 @@ export default function ChecksPanel(): React.JSX.Element { className="p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors" title="Refresh" onClick={() => void handleRefresh()} + disabled={isRefreshing} > - +