From 2ead377ebc15cc566684cf5f4657c3a1efa12857 Mon Sep 17 00:00:00 2001 From: claude Date: Sun, 7 Jun 2026 15:10:59 +0000 Subject: [PATCH] Fix stale error lines bleeding into next Typst compile log When typst watch doesn't emit "compiled with errors" after a failed compile, currentLines accumulates indefinitely. The next successful compile then flushes the buffer including the stale error from the prior cycle. Reset currentLines at the start of each compile cycle ("[HH:MM:SS] compiling ...") so each log only contains output from one compile. Co-Authored-By: Claude Sonnet 4.6 --- services/clsi/app/js/TypstRunner.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/clsi/app/js/TypstRunner.js b/services/clsi/app/js/TypstRunner.js index 242d81c1ce..12a3ff2d0b 100644 --- a/services/clsi/app/js/TypstRunner.js +++ b/services/clsi/app/js/TypstRunner.js @@ -17,6 +17,12 @@ const MAX_LOG_LINES = 500 // How long to wait for the watcher process to emit its first output. const WATCH_START_TIMEOUT_MS = 15_000 +// Matches the start-of-compile marker typst watch emits before each cycle: +// "[HH:MM:SS] compiling ..." +// Used to reset the line buffer so stale output from a failed compile that +// didn't emit a "compiled with errors" footer cannot bleed into the next log. +const COMPILE_START_RE = /^\[\d{2}:\d{2}:\d{2}\] compiling/ + // Matches the three terminal lines that typst watch emits at the end of each // compile cycle regardless of outcome: // "[HH:MM:SS] compiled successfully in 42ms" @@ -191,6 +197,12 @@ function _onWatcherData(compileName, chunk) { entry.accumulator = lines.pop() // keep the incomplete trailing fragment for (const line of lines) { + if (COMPILE_START_RE.test(line)) { + // New compile cycle — discard any output left over from a previous + // failed compile that didn't emit a "compiled with errors" footer. + entry.currentLines = [] + } + entry.currentLines.push(line) if (entry.currentLines.length > MAX_LOG_LINES) { entry.currentLines.shift()