🙌 OpenHands: AI-Driven Development
hotfix(forntend): Wait for runtime to start before fetching git changes for diff view (#7910)
sp.wack9544b37c8a14
diff --git a/frontend/src/hooks/query/use-get-git-changes.ts b/frontend/src/hooks/query/use-get-git-changes.tsindex cf2e99ba50..1ae3819c40 100644--- a/frontend/src/hooks/query/use-get-git-changes.ts+++ b/frontend/src/hooks/query/use-get-git-changes.ts@@ -1,20 +1,27 @@import { useQuery } from "@tanstack/react-query";import React from "react";+import { useSelector } from "react-redux";import OpenHands from "#/api/open-hands";import { useConversation } from "#/context/conversation-context";import { GitChange } from "#/api/open-hands.types";+import { RootState } from "#/store";+import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";export const useGetGitChanges = () => {const { conversationId } = useConversation();const [orderedChanges, setOrderedChanges] = React.useState<GitChange[]>([]);const previousDataRef = React.useRef<GitChange[]>(null);+ const { curAgentState } = useSelector((state: RootState) => state.agent);+ const runtimeIsActive = !RUNTIME_INACTIVE_STATES.includes(curAgentState);+const result = useQuery({queryKey: ["file_changes", conversationId],queryFn: () => OpenHands.getGitChanges(conversationId),retry: false,staleTime: 1000 * 60 * 5, // 5 minutesgcTime: 1000 * 60 * 15, // 15 minutes+ enabled: runtimeIsActive,meta: {disableToast: true,},diff --git a/frontend/src/i18n/declaration.ts b/frontend/src/i18n/declaration.tsindex 35a2c8cdfb..1cf81f641f 100644--- a/frontend/src/i18n/declaration.ts+++ b/frontend/src/i18n/declaration.ts@@ -415,4 +415,5 @@ export enum I18nKey {DIFF_VIEWER$NOT_A_GIT_REPO = "DIFF_VIEWER$NOT_A_GIT_REPO",DIFF_VIEWER$ASK_OH = "DIFF_VIEWER$ASK_OH",DIFF_VIEWER$NO_CHANGES = "DIFF_VIEWER$NO_CHANGES",+ DIFF_VIEWER$WAITING_FOR_RUNTIME = "DIFF_VIEWER$WAITING_FOR_RUNTIME",}diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.jsonindex 6a016e333f..ce151883f6 100644--- a/frontend/src/i18n/translation.json+++ b/frontend/src/i18n/translation.json@@ -6192,5 +6192,20 @@"fr": "OpenHands n'a pas encore apporté de modifications ...","tr": "OpenHands henüz herhangi bir değişiklik yapmadı ...","de": "OpenHands hat noch keine Änderungen vorgenommen..."+ },+ "DIFF_VIEWER$WAITING_FOR_RUNTIME": {+ "en": "Waiting for runtime to start...",+ "ja": "ランタイムの起動を待っています...",+ "zh-CN": "等待运行时启动...",+ "zh-TW": "等待運行時啟動...",+ "ko-KR": "런타임 시작 대기 중...",+ "no": "Venter på at kjøretid skal starte...",+ "it": "In attesa dell'avvio del runtime...",+ "pt": "Aguardando o tempo de execução para iniciar...",+ "es": "Esperando a que se inicie el tiempo de ejecución...",+ "ar": "في انتظار بدء وقت التشغيل...",+ "fr": "En attente du démarrage de l'exécution...",+ "tr": "Çalışma zamanının başlamasını bekliyor...",+ "de": "Warten auf den Start der Laufzeit..."}}\ No newline at end of filediff --git a/frontend/src/routes/editor.tsx b/frontend/src/routes/editor.tsxindex 4df529ce16..5508e6ccfb 100644--- a/frontend/src/routes/editor.tsx+++ b/frontend/src/routes/editor.tsx@@ -1,8 +1,11 @@import { useTranslation } from "react-i18next";+import { useSelector } from "react-redux";import { FileDiffViewer } from "#/components/features/diff-viewer/file-diff-viewer";import { retrieveAxiosErrorMessage } from "#/utils/retrieve-axios-error-message";import { useGetGitChanges } from "#/hooks/query/use-get-git-changes";import { I18nKey } from "#/i18n/declaration";+import { RootState } from "#/store";+import { RUNTIME_INACTIVE_STATES } from "#/types/agent-state";// Error message patternsconst GIT_REPO_ERROR_PATTERN = /not a git repository/i;@@ -19,11 +22,19 @@ function EditorScreen() {const { t } = useTranslation();const { data: gitChanges, isSuccess, isError, error } = useGetGitChanges();+ const { curAgentState } = useSelector((state: RootState) => state.agent);+ const runtimeIsActive = !RUNTIME_INACTIVE_STATES.includes(curAgentState);+const isNotGitRepoError =error && GIT_REPO_ERROR_PATTERN.test(retrieveAxiosErrorMessage(error));return (<main className="h-full overflow-y-scroll px-4 py-3 gap-3 flex flex-col">+ {!runtimeIsActive && (+ <StatusMessage>+ {t(I18nKey.DIFF_VIEWER$WAITING_FOR_RUNTIME)}+ </StatusMessage>+ )}{!isNotGitRepoError && error && (<StatusMessage>{retrieveAxiosErrorMessage(error)}</StatusMessage>)}@@ -35,7 +46,7 @@ function EditorScreen() {</StatusMessage>)}- {!isError && gitChanges?.length === 0 && (+ {runtimeIsActive && !isError && gitChanges?.length === 0 && (<StatusMessage>{t(I18nKey.DIFF_VIEWER$NO_CHANGES)}</StatusMessage>)}{isSuccess &&