Live-read all DOM attributes: forms and preloads too
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m49s

bindBoostForm re-reads method/action at submit time.
bind-preload-for re-reads verb-info and headers at preload time.
No closed-over stale values anywhere in the event binding system.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 02:11:09 +00:00
parent b85a46bb62
commit 04ff03f5d4
3 changed files with 29 additions and 24 deletions

View File

@@ -14,7 +14,7 @@
// =========================================================================
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
var SX_VERSION = "2026-03-07T02:03:55Z";
var SX_VERSION = "2026-03-07T02:10:28Z";
function isNil(x) { return x === NIL || x === null || x === undefined; }
function isSxTruthy(x) { return x !== false && !isNil(x); }
@@ -2185,14 +2185,12 @@ return postSwap(target); })) : NIL);
var bindPreloadFor = function(el) { return (function() {
var preloadAttr = domGetAttr(el, "sx-preload");
return (isSxTruthy(preloadAttr) ? (function() {
var info = getVerbInfo(el);
return (isSxTruthy(info) ? (function() {
var url = get(info, "url");
var headers = buildRequestHeaders(el, loadedComponentNames(), _cssHash);
var events = (isSxTruthy((preloadAttr == "mousedown")) ? ["mousedown", "touchstart"] : ["mouseover"]);
var debounceMs = (isSxTruthy((preloadAttr == "mousedown")) ? 0 : 100);
return bindPreload(el, events, debounceMs, function() { return doPreload(url, headers); });
})() : NIL);
return bindPreload(el, events, debounceMs, function() { return (function() {
var info = getVerbInfo(el);
return (isSxTruthy(info) ? doPreload(get(info, "url"), buildRequestHeaders(el, loadedComponentNames(), _cssHash)) : NIL);
})(); });
})() : NIL);
})(); };
@@ -3460,11 +3458,14 @@ callExpr.push(dictGet(kwargs, k)); } }
});
}
function bindBoostForm(form, method, action) {
function bindBoostForm(form, _method, _action) {
form.addEventListener("submit", function(e) {
e.preventDefault();
executeRequest(form, { method: method, url: action }).then(function() {
try { history.pushState({ sxUrl: action, scrollY: window.scrollY }, "", action); } catch (err) {}
// Re-read from element at submit time
var liveMethod = (form.getAttribute("method") || _method || "GET").toUpperCase();
var liveAction = form.getAttribute("action") || _action || location.href;
executeRequest(form, { method: liveMethod, url: liveAction }).then(function() {
try { history.pushState({ sxUrl: liveAction, scrollY: window.scrollY }, "", liveAction); } catch (err) {}
});
});
}