Skip to content

Commit 25fb4cf

Browse files
authored
fix(code): disable diff computing when review tab is not active (#1493)
## Problem random black screen / freezing / OOM issues: - me - https://posthog.slack.com/archives/C09G8Q32R6F/p1775212277963019 - #1485 i suspect it's related to the diff rendering... 1. file changes 2. file watcher sees it, emits an events 3. git queries are invalidated (getDiffCached, getDiffUnstaged) 4. review diffs have always-active observers on those queries, so they get refetched 5. refetch returns a full repo diff, which is then parsed and diff components re-render <!-- Who is this for and what problem does it solve? --> <!-- Closes #ISSUE_ID --> ## Changes disables the diff queries when the review tab is not active <!-- What did you change and why? --> <!-- If there are frontend changes, include screenshots. --> ## How did you test this? manually <!-- Describe what you tested -- manual steps, automated tests, or both. --> <!-- If you're an agent, only list tests you actually ran. -->
1 parent ea2b062 commit 25fb4cf

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

apps/code/src/renderer/features/code-review/components/ReviewPage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { makeFileKey } from "@features/git-interaction/utils/fileKey";
22
import { usePanelLayoutStore } from "@features/panels/store/panelLayoutStore";
3+
import { isTabActiveInTree } from "@features/panels/store/panelStoreHelpers";
34
import { useCwd } from "@features/sidebar/hooks/useCwd";
45
import type { parsePatchFiles } from "@pierre/diffs";
56
import { Flex, Text } from "@radix-ui/themes";
@@ -27,6 +28,11 @@ interface ReviewPageProps {
2728
export function ReviewPage({ taskId }: ReviewPageProps) {
2829
const repoPath = useCwd(taskId);
2930
const openFile = usePanelLayoutStore((s) => s.openFile);
31+
const isReviewTabActive = usePanelLayoutStore((s) => {
32+
const layout = s.getLayout(taskId);
33+
if (!layout) return false;
34+
return isTabActiveInTree(layout.panelTree, "review");
35+
});
3036
const onComment = useReviewComment(taskId);
3137

3238
const {
@@ -40,7 +46,7 @@ export function ReviewPage({ taskId }: ReviewPageProps) {
4046
allPaths,
4147
diffLoading,
4248
refetch,
43-
} = useReviewDiffs(repoPath);
49+
} = useReviewDiffs(repoPath, isReviewTabActive);
4450

4551
const {
4652
diffOptions,

apps/code/src/renderer/features/code-review/hooks/useReviewDiffs.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { useTRPC } from "@renderer/trpc/client";
77
import { useQuery } from "@tanstack/react-query";
88
import { useCallback, useMemo } from "react";
99

10-
export function useReviewDiffs(repoPath: string | undefined) {
10+
export function useReviewDiffs(
11+
repoPath: string | undefined,
12+
isActive: boolean,
13+
) {
1114
const trpc = useTRPC();
1215
const { changedFiles, changesLoading } = useGitQueries(repoPath);
1316
const hideWhitespace = useDiffViewerStore((s) => s.hideWhitespaceChanges);
@@ -25,7 +28,7 @@ export function useReviewDiffs(repoPath: string | undefined) {
2528
trpc.git.getDiffCached.queryOptions(
2629
{ directoryPath: repoPath as string, ignoreWhitespace: hideWhitespace },
2730
{
28-
enabled: !!repoPath && hasStagedFiles,
31+
enabled: isActive && !!repoPath && hasStagedFiles,
2932
staleTime: 30_000,
3033
refetchOnMount: "always",
3134
},
@@ -40,7 +43,7 @@ export function useReviewDiffs(repoPath: string | undefined) {
4043
trpc.git.getDiffUnstaged.queryOptions(
4144
{ directoryPath: repoPath as string, ignoreWhitespace: hideWhitespace },
4245
{
43-
enabled: !!repoPath,
46+
enabled: isActive && !!repoPath,
4447
staleTime: 30_000,
4548
refetchOnMount: "always",
4649
},

apps/code/src/renderer/features/panels/store/panelStoreHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ export function applyCleanupWithFallback(
237237
}
238238

239239
// Tab active state utilities
240-
function isTabActiveInTree(tree: PanelNode, tabId: string): boolean {
240+
export function isTabActiveInTree(tree: PanelNode, tabId: string): boolean {
241241
if (tree.type === "leaf") {
242242
return tree.content.activeTabId === tabId;
243243
}

0 commit comments

Comments
 (0)