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 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 15:39:07 +00:00
parent 7aea1f1be9
commit 5ede32e21c

View File

@@ -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);