Skip to content
TypeScript

fix(web): reopening the Changes panel refreshes its diff (#19550)

Ali Younes3fc8e5d65534
diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx
index ed05d56deea..94542eb625a 100644
--- a/apps/web/src/components/DiffPanel.tsx
+++ b/apps/web/src/components/DiffPanel.tsx
@@ -188,12 +188,14 @@ interface DiffPanelProps {
mode?: DiffPanelMode;
composerDraftTarget: ScopedThreadRef | DraftId;
workspaceMutationId: string | null;
+ visible: boolean;
}
export default function DiffPanel({
mode = "inline",
composerDraftTarget,
workspaceMutationId,
+ visible,
}: DiffPanelProps) {
const { resolvedTheme } = useTheme();
const settings = useClientSettings((settings) => ({
@@ -466,6 +468,38 @@ export default function DiffPanel({
preview: renderablePatch,
});
const refreshBranchDiffPreview = refreshPreviewQuery;
+ const previewOpenHandledRef = useRef(false);
+ const refreshDiffForWorkspaceMutation = useStableCallback(() => {
+ previewOpenHandledRef.current = true;
+ refreshBranchDiffPreview();
+ });
+
+ // A mutation refresh also satisfies revalidation for the current opening.
+ useWorkspaceMutationRefresh({
+ enabled: canRefreshGitDiff,
+ mutationId: workspaceMutationId,
+ refresh: refreshDiffForWorkspaceMutation,
+ resourceKey: `diff:${activeThreadRefreshKey ?? ""}`,
+ });
+
+ useEffect(() => {
+ if (!visible || !canReadFiles || !canRefreshGitDiff) {
+ previewOpenHandledRef.current = false;
+ return;
+ }
+ if (previewOpenHandledRef.current) return;
+ previewOpenHandledRef.current = true;
+ if (branchDiffPreview.data !== null && !branchDiffPreview.isPending) {
+ refreshBranchDiffPreview();
+ }
+ }, [
+ branchDiffPreview.data,
+ branchDiffPreview.isPending,
+ canReadFiles,
+ canRefreshGitDiff,
+ refreshBranchDiffPreview,
+ visible,
+ ]);
useEffect(() => {
if (!canRefreshGitDiff) return;
@@ -474,13 +508,6 @@ export default function DiffPanel({
return () => window.removeEventListener("focus", refreshOnFocus);
}, [canRefreshGitDiff, refreshBranchDiffPreview]);
- useWorkspaceMutationRefresh({
- enabled: canRefreshGitDiff,
- mutationId: workspaceMutationId,
- refresh: refreshBranchDiffPreview,
- resourceKey: `diff:${activeThreadRefreshKey ?? ""}`,
- });
-
const isRefreshingDiff = branchDiffPreview.isPending || areFilePatchesPending;
const renderableFileEntries = renderableFiles.map(getCachedFileEntry);
const diffFileKeys = renderableFileEntries.map((file) => file.fileKey);
diff --git a/apps/web/src/components/chat/RightPanelSurfaceContent.tsx b/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
index 3fed509f5dd..d8f512726de 100644
--- a/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
+++ b/apps/web/src/components/chat/RightPanelSurfaceContent.tsx
@@ -111,6 +111,7 @@ export function RightPanelSurfaceContent(props: {
mode="embedded"
composerDraftTarget={props.composerDraftTarget}
workspaceMutationId={props.workspaceMutationId}
+ visible={visible}
/>
</Suspense>
);