From 33dea073bbac5664ab585ee1b98fc4b68dd88799 Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Thu, 15 Oct 2026 01:52:08 +0800 Subject: [PATCH] perf(reading): load Markdown export only when requested --- .../reading/workspace/ReadingCompanion.tsx | 4 ++-- .../e2e/reading-citation-material.audit.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/web/components/reading/workspace/ReadingCompanion.tsx b/web/components/reading/workspace/ReadingCompanion.tsx index 8dcc5a1b7..75494b5e1 100644 --- a/web/components/reading/workspace/ReadingCompanion.tsx +++ b/web/components/reading/workspace/ReadingCompanion.tsx @@ -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 || diff --git a/web/tests/e2e/reading-citation-material.audit.ts b/web/tests/e2e/reading-citation-material.audit.ts index b282e0073..352db45d4 100644 --- a/web/tests/e2e/reading-citation-material.audit.ts +++ b/web/tests/e2e/reading-citation-material.audit.ts @@ -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]."); +});