Store auto-exec attempt on code block to avoid empty DOM elements

- Use codeBlock.dataset.autoExecAttempt to pass attempt number
- executeCodeBlock transfers attempt to results container
- No longer pre-creates empty results container
- Clean up data attribute after use
This commit is contained in:
Russell Ballestrini 2025-11-30 15:17:27 -05:00
parent 5c25229429
commit 22ed72da7e

View file

@ -954,30 +954,11 @@ socket.on("chat_message", (data) => {
if (runButton) {
console.log(`Auto-executing fixed code (attempt ${autoExecData.attempt}/3)...`);
// Find or create results container and set attempt count
// Results container goes after the button container (which is after the <pre>)
let resultsContainer = buttonContainer?.nextSibling;
if (!resultsContainer || !resultsContainer.classList || !resultsContainer.classList.contains('code-execution-results')) {
resultsContainer = document.createElement('div');
resultsContainer.classList.add('code-execution-results');
resultsContainer.style.marginTop = '10px';
resultsContainer.style.padding = '10px';
resultsContainer.style.backgroundColor = 'var(--bg-code)';
resultsContainer.style.borderRadius = '5px';
resultsContainer.style.fontFamily = 'monospace';
resultsContainer.style.fontSize = '14px';
resultsContainer.style.whiteSpace = 'pre-wrap';
resultsContainer.style.wordWrap = 'break-word';
// Insert after button container
if (buttonContainer && buttonContainer.nextSibling) {
buttonContainer.parentNode.insertBefore(resultsContainer, buttonContainer.nextSibling);
} else if (buttonContainer) {
buttonContainer.parentNode.appendChild(resultsContainer);
}
}
resultsContainer.dataset.fixAttempts = autoExecData.attempt.toString();
// Store the attempt count so executeCodeBlock can pick it up
// We'll use a data attribute on the code block itself
codeBlock.dataset.autoExecAttempt = autoExecData.attempt.toString();
// Trigger execution
// Trigger execution - it will create its own results container
runButton.click();
}
}, 100); // Delay to ensure buttons are fully rendered
@ -1514,6 +1495,12 @@ async function executeCodeBlock(code, blockElement, playButton) {
blockElement.parentNode.insertBefore(resultsContainer, blockElement.nextSibling);
}
// Check if this is an auto-exec from a fix and set the attempt counter
if (blockElement.dataset.autoExecAttempt) {
resultsContainer.dataset.fixAttempts = blockElement.dataset.autoExecAttempt;
delete blockElement.dataset.autoExecAttempt; // Clean up after use
}
// Clear previous results
resultsContainer.innerHTML = '<div style="color: var(--text-muted);">Executing code...</div>';