Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(preview): keep Save and Retry reachable while loading and with long names
AdityaUmale5f07b941ee93
diff --git a/src/components/MarkdownFilePreview.test.ts b/src/components/MarkdownFilePreview.test.tsindex 2246f0f6fd..8fb9e187e9 100644--- a/src/components/MarkdownFilePreview.test.ts+++ b/src/components/MarkdownFilePreview.test.ts@@ -3,7 +3,7 @@ import { renderToStaticMarkup } from "react-dom/server";import { describe, expect, it } from "vitest";import { AttachedFileChip } from "./AttachmentPreview";import { isMarkdownFile } from "./HtmlFilePreview";-import { MARKDOWN_PREVIEW_MAX_BYTES, MarkdownFileView } from "./MarkdownFilePreview";+import MarkdownFileContent, { MARKDOWN_PREVIEW_MAX_BYTES, MarkdownFileView } from "./MarkdownFilePreview";import { readTableResponse } from "./TableFilePreview";const message = { threadId: "t", messageId: "m" };@@ -58,4 +58,14 @@ describe("MarkdownFileView (#4765)", () => {const signal = new AbortController().signal;await expect(readTableResponse(new Response(new Uint8Array(MARKDOWN_PREVIEW_MAX_BYTES + 1)), signal, MARKDOWN_PREVIEW_MAX_BYTES)).rejects.toThrow("size");});++ it("keeps Save and Retry on screen while the file is still loading, wrapping for long names", () => {+ const name = `${"a".repeat(120)}.md`;+ const html = renderToStaticMarkup(createElement(MarkdownFileContent, { path: `/workspace/${name}`, name, message }));+ expect(html).toContain('role="status"');+ expect(html).toContain(`Save a copy of ${name}`);+ expect(html).toContain(">Retry</button>");+ expect(html).toMatch(/class="mt-3 flex flex-wrap justify-center gap-2"/);+ expect(html).not.toMatch(/role="status"[^>]*>(?:(?!<\/span>)[^])*<button/);+ });});diff --git a/src/components/MarkdownFilePreview.tsx b/src/components/MarkdownFilePreview.tsxindex 621153b9a1..1a6912012e 100644--- a/src/components/MarkdownFilePreview.tsx+++ b/src/components/MarkdownFilePreview.tsx@@ -30,10 +30,10 @@ export default function MarkdownFileContent({ path, name, message }: { path: str})();return () => controller.abort();}, [path, message.threadId, message.messageId, attempt]);- const retry = <button type="button" className="rounded-lg border border-hairline px-3 py-2 hover:bg-raised" onClick={() => setAttempt(attempt + 1)}>{t("chat.retry")}</button>;- const saveFailed = save.state === "failed" && <p role="alert" className="mt-2 text-[12px] text-danger">{save.reason}</p>;- if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="mb-3 text-ink-secondary">{t(error === "size" ? "markdown.tooLarge" : "markdown.loadFailed")}</p><div className="flex justify-center gap-2"><button type="button" className="inline-flex items-center gap-1.5 rounded-lg border border-hairline px-3 py-2 hover:bg-raised" disabled={save.state === "saving"} onClick={() => void save.save()}><Download size={14} />{t("attach.saveAria", { name })}</button>{retry}</div>{saveFailed}</div>;- if (source === null) return <div role="status" className="p-12 text-center text-sm text-ink-secondary"><span className="inline-flex items-center gap-2"><LoaderCircle size={16} className="animate-spin" />{t("markdown.loading")}</span>{saveFailed}</div>;+ // Save and Retry stay on screen while loading too, so a stalled request never leaves only a spinner; they wrap so a long name can't push Retry off a narrow dialog.+ const recovery = <><div className="mt-3 flex flex-wrap justify-center gap-2"><button type="button" className="inline-flex max-w-full min-w-0 items-center gap-1.5 rounded-lg border border-hairline px-3 py-2 hover:bg-raised" disabled={save.state === "saving"} onClick={() => void save.save()}><Download size={14} className="shrink-0" /><span className="min-w-0 break-all">{t("attach.saveAria", { name })}</span></button><button type="button" className="rounded-lg border border-hairline px-3 py-2 hover:bg-raised" onClick={() => setAttempt(attempt + 1)}>{t("chat.retry")}</button></div>{save.state === "failed" && <p role="alert" className="mt-2 text-[12px] text-danger">{save.reason}</p>}</>;+ if (error) return <div className="p-8 text-center text-sm"><p role="alert" className="text-ink-secondary">{t(error === "size" ? "markdown.tooLarge" : "markdown.loadFailed")}</p>{recovery}</div>;+ if (source === null) return <div className="p-12 text-center text-sm text-ink-secondary"><span role="status" className="inline-flex items-center gap-2"><LoaderCircle size={16} className="animate-spin" />{t("markdown.loading")}</span>{recovery}</div>;return <div className="flex flex-col gap-2"><div className="flex items-center justify-end gap-1"><button type="button" className="table-action" aria-pressed={showSource} aria-label={t(showSource ? "markdown.rendered" : "html.source")} title={t(showSource ? "markdown.rendered" : "html.source")} onClick={() => setShowSource(!showSource)}>{showSource ? <Eye size={14} /> : <Code2 size={14} />}</button>