Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

perf(reading): load Markdown export only when requested

Bingxi Zhao (Frank)33dea073bbac
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].");
+});