Skip to content

Commit 994c9a7

Browse files
committed
Fixes
1 parent d89b9e1 commit 994c9a7

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

src/app/api/diff/[owner]/[repository]/[...path]/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { NextRequest, NextResponse } from "next/server"
2-
import { session } from "@/composition"
2+
import { session, diffCalculator } from "@/composition"
33
import { makeUnauthenticatedAPIErrorResponse } from "@/common"
4-
import { diffCalculator } from "@/composition"
54

65
interface GetDiffParams {
76
owner: string

src/features/projects/data/GitHubRepositoryDataSource.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ export default class GitHubProjectDataSource
197197
}
198198

199199
// Map PRs by their head branch name for quick lookup
200-
response.repository.pullRequests.edges.forEach((edge: any) => {
200+
const pullRequestEdges =
201+
response.repository.pullRequests.edges as Edge<GraphQLPullRequest>[];
202+
203+
pullRequestEdges.forEach((edge) => {
201204
const pr = edge.node;
202205
pullRequests.set(pr.headRefName, {
203206
headRefName: pr.headRefName,

src/features/sidebar/data/useDiff.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,28 @@ export default function useDiff() {
1616

1717
useEffect(() => {
1818
if (!diffUrl) {
19-
setData({ changes: [] })
20-
setLoading(false)
21-
setError(null)
2219
return
2320
}
2421

25-
setLoading(true)
26-
setError(null)
22+
let isCancelled = false
23+
24+
Promise.resolve().then(() => {
25+
if (isCancelled) {
26+
return
27+
}
28+
29+
setLoading(true)
30+
setError(null)
31+
setData(null)
32+
})
2733

2834
fetch(diffUrl)
2935
.then(res => res.json())
3036
.then(result => {
37+
if (isCancelled) {
38+
return
39+
}
40+
3141
if (result.error) {
3242
setData(null)
3343
setError(result.error)
@@ -38,12 +48,26 @@ export default function useDiff() {
3848
setLoading(false)
3949
})
4050
.catch(err => {
51+
if (isCancelled) {
52+
return
53+
}
54+
4155
console.error("Failed to fetch diff:", err)
4256
setData(null)
4357
setError("We couldn't load the diff right now. Please try again later.")
4458
setLoading(false)
4559
})
60+
61+
return () => {
62+
isCancelled = true
63+
}
4664
}, [diffUrl])
4765

48-
return { data, loading, changes: data?.changes || [], error }
66+
const hasDiffUrl = Boolean(diffUrl)
67+
const resolvedData = hasDiffUrl ? data : { changes: [] }
68+
const resolvedChanges = resolvedData?.changes ?? []
69+
const resolvedLoading = hasDiffUrl ? loading : false
70+
const resolvedError = hasDiffUrl ? error : null
71+
72+
return { data: resolvedData, loading: resolvedLoading, changes: resolvedChanges, error: resolvedError }
4973
}

src/features/sidebar/view/SecondarySplitHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ const ToggleDiffButton = ({
141141
const [isMac, setIsMac] = useState(false);
142142
useEffect(() => {
143143
// checkIsMac uses window so we delay the check.
144-
setIsMac(checkIsMac());
145-
}, [isMac, setIsMac]);
144+
const timeout = window.setTimeout(() => {
145+
setIsMac(checkIsMac());
146+
}, 0);
147+
return () => window.clearTimeout(timeout);
148+
}, []);
146149
const isSidebarTogglable = useContext(SidebarTogglableContext);
147150
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + K)`;
148151
const tooltip = isDiffbarOpen ? "Hide changes" : "Show changes";

0 commit comments

Comments
 (0)