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()