Merge pull request #1965 from HKUDS/codex/reading-export-lazy

perf(reading): load Markdown export only when requested
This commit is contained in:
Bingxi Zhao
2026-10-15 02:18:12 +08:00
committed by GitHub
2 changed files with 19 additions and 2 deletions

View File

@@ -45,7 +45,6 @@ import { useChatAutoScroll } from "@/hooks/useChatAutoScroll";
import { useMeasuredHeight } from "@/hooks/useMeasuredHeight";
import { useResearchOutlineContinuation } from "@/hooks/useResearchOutlineContinuation";
import { buildChatOutline, scrollToChatTurn } from "@/lib/chat-outline";
import { downloadChatMarkdown } from "@/lib/chat-export";
import { copyText } from "@/lib/clipboard";
import { buildConversationNotebookSave } from "@/lib/conversation-notebook-save";
import { setReadingViewport } from "@/lib/reading-turn-state";
@@ -281,8 +280,9 @@ export function ReadingCompanion({
[state.messages],
);
const downloadMarkdown = useCallback(() => {
const downloadMarkdown = useCallback(async () => {
if (!state.messages.length) return;
const { downloadChatMarkdown } = await import("@/lib/chat-export");
downloadChatMarkdown(state.messages, {
title:
activeConversation?.title ||

View File

@@ -1,3 +1,4 @@
import { readFile } from "node:fs/promises";
import { expect, test } from "@playwright/test";
import { emptyTaskBoard } from "./fixtures/task-board";
@@ -228,3 +229,19 @@ test("historical citation reopens its turn material and unsupported locator stay
await expect(page.getByText("Verified source material text.")).toBeVisible();
await expect(page.getByText("Wrong material text.")).toHaveCount(0);
});
test("downloads the persisted reading conversation as Markdown", async ({ page }) => {
await page.goto(`/learning/reading/${WORKSPACE_ID}/sessions/${SESSION_ID}`, { waitUntil: "domcontentloaded" });
await expect(page.getByRole("link", { name: "p.2" })).toBeVisible();
await page.getByRole("button", { name: "More", exact: true }).click();
const exported = page.waitForEvent("download");
await page.getByRole("button", { name: "Download Markdown", exact: true }).click();
const download = await exported;
expect(download.suggestedFilename()).toMatch(/\.md$/);
const downloadedPath = await download.path();
expect(downloadedPath).not.toBeNull();
const markdown = await readFile(downloadedPath!, "utf8");
expect(markdown).toContain("Where is the source passage?");
expect(markdown).toContain("The grounded passage is here [p.2]. A guess is [p.1].");
});