🙌 OpenHands: AI-Driven Development
fix(changes): show placeholder instead of error toast when expanding a deleted file (#285)
Robert Brennana7b35f7098f7
diff --git a/AGENTS.md b/AGENTS.mdindex 73a291715f..1c76350631 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -194,4 +194,6 @@- Conversation right-panel regression note: `ConversationTabs` now owns the moved refresh/build buttons, so `__tests__/components/features/conversation/conversation-tabs.test.tsx` should cover that behavior directly. In those tests, seed both the persisted conversation-state key and the Zustand store (`selectedTab`, `isRightPanelShown`, `hasRightPanelToggled`) — the component sync effect currently restores `hasRightPanelToggled` from localStorage, not `isRightPanelShown`, so localStorage alone will not make a tab read as active.+- Changes tab / `FileDiffViewer` deleted-file note: the agent-server's `/api/git/diff` endpoint calls `path.exists()` first (see `openhands-sdk/openhands/sdk/git/git_diff.py` → `get_git_diff`), so requesting a diff for a `D` (deleted) file returns `GitPathError` → HTTP 400 and trips the global QueryCache error toast. `useUnifiedGitDiff` disables the query when `type === "D"` and `FileDiffViewer` renders a localized "file deleted" placeholder (`DIFF_VIEWER$FILE_DELETED`, `data-testid="file-deleted-message"`) instead of the view-mode toolbar / Monaco editor for that case.+- Onboarding modal: `src/components/features/onboarding/onboarding-modal.tsx` is a 4-step welcome flow rendered by `<OnboardingHost />` (mounted on the home route) and gated by the `openhands-onboarded` localStorage flag (`use-onboarding-completion.ts`). The four steps live under `steps/`: choose-agent (Step 0 – OpenHands selectable, Claude Code & Codex disabled with a "coming soon" note), check-backend (embeds the new `BackendForm` extracted from `backend-form-modal.tsx` plus a colored connection banner driven by `useBackendsHealth`), setup-llm (renders `<LlmSettingsScreen onSaveSuccess={onNext} />` so the existing settings UI keeps owning validation), and say-hello (text input pre-filled from `ONBOARDING$HELLO_DEFAULT_MESSAGE`, launches a no-workspace conversation via `useCreateConversation` and closes the modal). Animation: all four panels are mounted as siblings inside a horizontal rail; advancing/retreating just sets `currentStep`, which translates the rail by `-(step * 100)%` for the slide effect. Progress is rendered by `OnboardingProgressBar` with `data-state` per segment (`completed` | `current` | `upcoming`). When extending, refactor `BackendFormModal` carefully — the inner `BackendForm` is the public surface used both by the modal and by `CheckBackendStep`; the modal version still owns dirty/save tracking so it keeps "Save"/"Cancel" footer behavior.diff --git a/__tests__/components/features/diff-viewer/file-diff-viewer.test.tsx b/__tests__/components/features/diff-viewer/file-diff-viewer.test.tsxindex 36379cc593..97090455fc 100644--- a/__tests__/components/features/diff-viewer/file-diff-viewer.test.tsx+++ b/__tests__/components/features/diff-viewer/file-diff-viewer.test.tsx@@ -148,6 +148,25 @@ describe("FileDiffViewer", () => {expect(screen.queryByTestId("markdown-preview")).not.toBeInTheDocument();});+ it("renders a 'file deleted' placeholder when expanded for a deleted file", async () => {+ // Simulate the hook short-circuiting the API call for deleted files.+ mockDiff = undefined as unknown as typeof MOCK_DIFF;+ mockIsSuccess = false;+ const user = userEvent.setup();+ render(<FileDiffViewer path="src/removed.ts" type="D" />);++ await expand(user);++ expect(screen.getByTestId("file-deleted-message")).toBeInTheDocument();+ expect(screen.queryByTestId("file-diff-viewer")).not.toBeInTheDocument();+ expect(screen.queryByTestId("file-single-viewer")).not.toBeInTheDocument();+ // View-mode toolbar should not render for deleted files since there is+ // nothing to switch between.+ expect(screen.queryByTestId("view-mode-old")).not.toBeInTheDocument();+ expect(screen.queryByTestId("view-mode-diff")).not.toBeInTheDocument();+ expect(screen.queryByTestId("view-mode-new")).not.toBeInTheDocument();+ });+it("highlights the active view mode button", async () => {const user = userEvent.setup();render(<FileDiffViewer path="src/index.ts" type="M" />);diff --git a/src/components/features/diff-viewer/file-diff-viewer.tsx b/src/components/features/diff-viewer/file-diff-viewer.tsxindex 693079a163..e0cfb130be 100644--- a/src/components/features/diff-viewer/file-diff-viewer.tsx+++ b/src/components/features/diff-viewer/file-diff-viewer.tsx@@ -1,6 +1,7 @@import { DiffEditor, Editor, Monaco } from "@monaco-editor/react";import React from "react";import { editor as editor_t } from "monaco-editor";+import { useTranslation } from "react-i18next";import {LuFileDiff,LuFileMinus,@@ -11,6 +12,7 @@ import {} from "react-icons/lu";import { IconType } from "react-icons/lib";import { GitChangeStatus } from "#/api/open-hands.types";+import { I18nKey } from "#/i18n/declaration";import { getLanguageFromPath } from "#/utils/get-language-from-path";import { cn } from "#/utils/utils";import ChevronUp from "#/icons/chveron-up.svg?react";@@ -73,6 +75,7 @@ export interface FileDiffViewerProps {}export function FileDiffViewer({ path, type }: FileDiffViewerProps) {+ const { t } = useTranslation("openhands");const [isCollapsed, setIsCollapsed] = React.useState(true);const [editorHeight, setEditorHeight] = React.useState(400);const [viewMode, setViewMode] = React.useState<ViewMode>("diff");@@ -211,7 +214,7 @@ export function FileDiffViewer({ path, type }: FileDiffViewerProps) {<span className="text-sm w-full text-content flex items-center gap-2">{isFetchingData ? <LoadingSpinner className="w-4 h-4" /> : statusIcon}<strong className="w-full truncate font-medium">{filePath}</strong>- {!isCollapsed && (+ {!isCollapsed && !isDeleted && (<spanclassName="flex items-center gap-0.5 shrink-0"onClick={(e) => e.stopPropagation()}@@ -245,7 +248,16 @@ export function FileDiffViewer({ path, type }: FileDiffViewerProps) {</span></div>- {isSuccess && !isCollapsed && renderContent()}+ {!isCollapsed && isDeleted && (+ <div+ data-testid="file-deleted-message"+ className="w-full border-b border-[#474A54] p-4 bg-neutral-900 text-[#8D95A9] text-sm"+ >+ {t(I18nKey.DIFF_VIEWER$FILE_DELETED)}+ </div>+ )}++ {!isCollapsed && !isDeleted && isSuccess && renderContent()}</div>);}diff --git a/src/hooks/query/use-unified-git-diff.ts b/src/hooks/query/use-unified-git-diff.tsindex 754255e220..354ba8999d 100644--- a/src/hooks/query/use-unified-git-diff.ts+++ b/src/hooks/query/use-unified-git-diff.ts@@ -26,6 +26,12 @@ export const useUnifiedGitDiff = (config: UseUnifiedGitDiffConfig) => {return `${gitPath}/${config.filePath}`;}, [selectedRepository, config.filePath, workingDir]);+ // Deleted files no longer exist on disk, so the agent server's+ // `/api/git/diff` endpoint returns a `GitPathError` (HTTP 400) for them.+ // Skip the request entirely and let the UI render a "file deleted"+ // placeholder instead of triggering an error toast.+ const isDeleted = config.type === "D";+return useQuery({queryKey: ["file_diff",@@ -43,7 +49,7 @@ export const useUnifiedGitDiff = (config: UseUnifiedGitDiffConfig) => {absoluteFilePath,);},- enabled: config.enabled,+ enabled: config.enabled && !isDeleted,staleTime: 1000 * 60 * 5, // 5 minutesgcTime: 1000 * 60 * 15, // 15 minutes});diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 33e7dcc159..19e4413ccb 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -14964,6 +14964,23 @@"uk": "OpenHands ще не вніс жодних змін","ca": "L'OpenHands encara no ha fet cap canvi"},+ "DIFF_VIEWER$FILE_DELETED": {+ "en": "This file was deleted. Its previous contents are no longer available for preview.",+ "ja": "このファイルは削除されました。以前の内容はプレビューできません。",+ "zh-CN": "此文件已被删除,无法预览其先前内容。",+ "zh-TW": "此檔案已被刪除,無法預覽其先前內容。",+ "ko-KR": "이 파일은 삭제되었습니다. 이전 내용은 더 이상 미리 볼 수 없습니다.",+ "no": "Denne filen ble slettet. Det tidligere innholdet er ikke lenger tilgjengelig for forhåndsvisning.",+ "it": "Questo file è stato eliminato. Il contenuto precedente non è più disponibile per l'anteprima.",+ "pt": "Este arquivo foi excluído. Seu conteúdo anterior não está mais disponível para visualização.",+ "es": "Este archivo fue eliminado. Su contenido anterior ya no está disponible para previsualización.",+ "ar": "تم حذف هذا الملف. لم يعد محتواه السابق متاحًا للمعاينة.",+ "fr": "Ce fichier a été supprimé. Son contenu précédent n'est plus disponible pour l'aperçu.",+ "tr": "Bu dosya silindi. Önceki içeriği artık önizleme için kullanılamıyor.",+ "de": "Diese Datei wurde gelöscht. Ihr früherer Inhalt steht nicht mehr zur Vorschau zur Verfügung.",+ "uk": "Цей файл було видалено. Його попередній вміст більше недоступний для перегляду.",+ "ca": "Aquest fitxer s'ha eliminat. El seu contingut anterior ja no està disponible per a la previsualització."+ },"DIFF_VIEWER$WAITING_FOR_RUNTIME": {"en": "Waiting for runtime to start...","ja": "ランタイムの起動を待っています...",