Fix HTML truncation to avoid cutting inside tags

This commit is contained in:
Jared Miller 2026-01-31 09:12:20 -05:00
parent 3e5afbd5a8
commit a14decf2bc
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -1433,7 +1433,12 @@
// Soft cap to prevent unbounded growth in DOM and memory
const MAX_OUTPUT_CHARS = 200000; // ~200KB of HTML per session
if (session.output.length > MAX_OUTPUT_CHARS) {
const start = session.output.length - MAX_OUTPUT_CHARS;
let start = session.output.length - MAX_OUTPUT_CHARS;
// Find safe cut point - don't cut inside an HTML tag
const firstTagEnd = session.output.indexOf('>', start);
if (firstTagEnd !== -1 && firstTagEnd < start + 100) {
start = firstTagEnd + 1;
}
session.output = session.output.slice(start);
// Reset DOM to trimmed content and sync rendered length
$output.innerHTML = session.output;