Cleanup dom
This commit is contained in:
parent
f2c3f6f067
commit
721bff81d0
1 changed files with 18 additions and 1 deletions
|
|
@ -1071,9 +1071,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectSSE() {
|
function connectSSE() {
|
||||||
|
// Clean up any prior connection attempt
|
||||||
if (state.eventSource) {
|
if (state.eventSource) {
|
||||||
state.eventSource.close();
|
state.eventSource.close();
|
||||||
}
|
}
|
||||||
|
if (state.reconnectTimeout) {
|
||||||
|
clearTimeout(state.reconnectTimeout);
|
||||||
|
state.reconnectTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
const es = new EventSource('/events');
|
const es = new EventSource('/events');
|
||||||
|
|
||||||
|
|
@ -1091,6 +1096,7 @@
|
||||||
console.debug('SSE error, reconnecting...');
|
console.debug('SSE error, reconnecting...');
|
||||||
setStatus(false);
|
setStatus(false);
|
||||||
es.close();
|
es.close();
|
||||||
|
state.eventSource = null;
|
||||||
if (!state.reconnectTimeout) {
|
if (!state.reconnectTimeout) {
|
||||||
state.reconnectTimeout = setTimeout(() => connectSSE(), 2000);
|
state.reconnectTimeout = setTimeout(() => connectSSE(), 2000);
|
||||||
}
|
}
|
||||||
|
|
@ -1419,7 +1425,18 @@
|
||||||
// Append only new content since last render
|
// Append only new content since last render
|
||||||
const newChunk = session.output.slice(session.outputRenderedLength);
|
const newChunk = session.output.slice(session.outputRenderedLength);
|
||||||
if (newChunk) {
|
if (newChunk) {
|
||||||
$output.innerHTML += newChunk;
|
// More efficient than innerHTML += as it avoids reparsing existing content
|
||||||
|
$output.insertAdjacentHTML('beforeend', newChunk);
|
||||||
|
session.outputRenderedLength = session.output.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
session.output = session.output.slice(start);
|
||||||
|
// Reset DOM to trimmed content and sync rendered length
|
||||||
|
$output.innerHTML = session.output;
|
||||||
session.outputRenderedLength = session.output.length;
|
session.outputRenderedLength = session.output.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue