From 22ed72da7e01cddb6d8c5b0916270407fd83866b Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 30 Nov 2025 15:17:27 -0500 Subject: [PATCH] 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 --- templates/chat.html | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/templates/chat.html b/templates/chat.html index 5ddfc94..468448d 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -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
)
-                        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 = '
Executing code...
';