From bfba86a01b1e8e6dc11bd1fe81344e945cd17d97 Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 20 Jun 2026 19:03:46 -0400 Subject: [PATCH] perf(preview): typeset only the active chapter in live preview --- src/components/Dock.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/Dock.tsx b/src/components/Dock.tsx index 44bce0e..6ece4f3 100644 --- a/src/components/Dock.tsx +++ b/src/components/Dock.tsx @@ -3,7 +3,7 @@ import { generateHTML } from "@tiptap/core"; import { useBook } from "../store/useBook"; import type { TrimSize } from "../model/book"; import { editorExtensions } from "../editor/extensions"; -import { bookToPdfInputs } from "../export/typst"; +import { chapterToPdfInputs } from "../export/typst"; import { compilePdf, isDesktop } from "../ipc"; import { PdfPreview } from "./PdfPreview"; @@ -39,6 +39,7 @@ export function Dock() { function PdfDock() { const book = useBook((s) => s.book); + const activeChapterId = useBook((s) => s.activeChapterId); const [pdf, setPdf] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); @@ -46,10 +47,11 @@ function PdfDock() { useEffect(() => { if (!book) return; + const idx = Math.max(0, book.chapters.findIndex((c) => c.id === activeChapterId)); clearTimeout(timer.current); setBusy(true); timer.current = setTimeout(() => { - const { source, images } = bookToPdfInputs(book); + const { source, images } = chapterToPdfInputs(book, idx); compilePdf(source, images) .then((bytes) => { setPdf(bytes); @@ -59,7 +61,7 @@ function PdfDock() { .finally(() => setBusy(false)); }, 350); return () => clearTimeout(timer.current); - }, [book]); + }, [book, activeChapterId]); return (