// Logs build/render errors exactly once while the same error state persists. // // Dev recovery paths (watcher, request retries, post-build HMR) re-attempt a // rebuild for every file edit and request while a syntax error is still in the // file. Without deduplication that one error is printed again on every // attempt — an endless spiral of identical log lines. The signature is // cleared after a successful build, so the same error later (after a fix and // regression) is logged again as a new incident. let last_build_error_signature; function errorSignature(errors) { return errors .map((e) => { const text = e.text || e.message || e.id || ""; const loc = e.location ? `${e.location.file}:${e.location.line}:${e.location.column}` : ""; return `${text}${loc}`; }) .join("\n---\n"); } /** * Logs each error once — identical error sets are suppressed until the * signature changes or `resetBuildErrorLog()` is called (after a successful * build). Returns true when something was logged. */ export function logBuildErrorsOnce(errors, logLine = (line) => console.error(line)) { if (!errors || errors.length === 0) return false; const signature = errorSignature(errors); if (signature === last_build_error_signature) return false; last_build_error_signature = signature; for (const e of errors) { const text = e.text || e.message || e.id || "Build Error"; const loc = e.location ? ` (${e.location.file}:${e.location.line}:${e.location.column})` : ""; logLine(`${text}${loc}`); } return true; } /** * Clears the dedup state so a new incident with the same signature is logged * again. Call after a successful build. */ export function resetBuildErrorLog() { last_build_error_signature = undefined; }