From 5ede32e21c42c39bc5c8c6e2cd724c7a7a858000 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 1 Mar 2026 15:39:07 +0000 Subject: [PATCH] Activate regular script tags after sx swap operations Scripts inserted via innerHTML/insertAdjacentHTML don't execute. Add _activateScripts() to _swapContent that recreates script tags (without type or type=text/javascript) as live elements. This fixes editor.js not loading when navigating to edit pages via sx-get. Co-Authored-By: Claude Opus 4.6 --- shared/static/scripts/sx.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shared/static/scripts/sx.js b/shared/static/scripts/sx.js index b139d1d..669f773 100644 --- a/shared/static/scripts/sx.js +++ b/shared/static/scripts/sx.js @@ -1719,6 +1719,20 @@ // ---- Swap engine ------------------------------------------------------ + /** Scripts inserted via innerHTML/insertAdjacentHTML don't execute. + * Recreate them as live elements so the browser fetches & runs them. */ + function _activateScripts(root) { + var dead = root.querySelectorAll("script:not([type]), script[type='text/javascript']"); + for (var i = 0; i < dead.length; i++) { + var d = dead[i]; + var live = document.createElement("script"); + for (var a = 0; a < d.attributes.length; a++) + live.setAttribute(d.attributes[a].name, d.attributes[a].value); + live.textContent = d.textContent; + d.parentNode.replaceChild(live, d); + } + } + function _swapContent(target, html, strategy) { switch (strategy) { case "innerHTML": @@ -1730,6 +1744,7 @@ tgt.insertAdjacentHTML("afterend", html); parent.removeChild(tgt); // Process parent to catch all newly inserted siblings + _activateScripts(parent); Sx.processScripts(parent); Sx.hydrate(parent); SxEngine.process(parent); @@ -1752,6 +1767,7 @@ default: target.innerHTML = html; } + _activateScripts(target); Sx.processScripts(target); Sx.hydrate(target); SxEngine.process(target);