Add explicit logging for route decisions in bind-event

- Log "sx:route server fetch <url>" when falling back to network
- Use console.error for eval errors (not console.warn)
- Restructure bind-event to separate client route check from &&-chain

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 21:44:55 +00:00
parent 3a8ee0dbd6
commit 2a978e6e9f
3 changed files with 33 additions and 21 deletions

View File

@@ -14,7 +14,7 @@
// =========================================================================
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
var SX_VERSION = "2026-03-06T21:38:19Z";
var SX_VERSION = "2026-03-06T21:44:48Z";
function isNil(x) { return x === NIL || x === null || x === undefined; }
function isSxTruthy(x) { return x !== false && !isNil(x); }
@@ -1850,7 +1850,14 @@ return postSwap(target); });
return (isSxTruthy((val == lastVal)) ? (shouldFire = false) : (lastVal = val));
})();
}
return (isSxTruthy(shouldFire) ? ((isSxTruthy(sxOr((eventName == "submit"), (isSxTruthy((eventName == "click")) && domHasAttr(el, "href")))) ? preventDefault_(e) : NIL), (isSxTruthy((isSxTruthy((eventName == "click")) && isSxTruthy((get(verbInfo, "method") == "GET")) && isSxTruthy(domHasAttr(el, "href")) && isSxTruthy(!get(mods, "delay")) && tryClientRoute(urlPathname(get(verbInfo, "url"))))) ? (browserPushState(get(verbInfo, "url")), browserScrollTo(0, 0)) : (isSxTruthy(get(mods, "delay")) ? (clearTimeout_(timer), (timer = setTimeout_(function() { return executeRequest(el, verbInfo, NIL); }, get(mods, "delay")))) : executeRequest(el, verbInfo, NIL)))) : NIL);
return (isSxTruthy(shouldFire) ? ((isSxTruthy(sxOr((eventName == "submit"), (isSxTruthy((eventName == "click")) && domHasAttr(el, "href")))) ? preventDefault_(e) : NIL), (function() {
var isGetLink = (isSxTruthy((eventName == "click")) && isSxTruthy((get(verbInfo, "method") == "GET")) && isSxTruthy(domHasAttr(el, "href")) && !get(mods, "delay"));
var clientRouted = false;
if (isSxTruthy(isGetLink)) {
clientRouted = tryClientRoute(urlPathname(get(verbInfo, "url")));
}
return (isSxTruthy(clientRouted) ? (browserPushState(get(verbInfo, "url")), browserScrollTo(0, 0)) : ((isSxTruthy(isGetLink) ? logInfo((String("sx:route server fetch ") + String(get(verbInfo, "url")))) : NIL), (isSxTruthy(get(mods, "delay")) ? (clearTimeout_(timer), (timer = setTimeout_(function() { return executeRequest(el, verbInfo, NIL); }, get(mods, "delay")))) : executeRequest(el, verbInfo, NIL))));
})()) : NIL);
})(); }, (isSxTruthy(get(mods, "once")) ? {["once"]: true} : NIL)) : NIL);
})(); };
@@ -3101,7 +3108,7 @@ callExpr.push(dictGet(kwargs, k)); } }
}
return sxRenderWithEnv(source, merged);
} catch (e) {
console.warn("sx:route eval error", e);
console.error("[sx-ref] sx:route eval error for:", source, e);
return NIL;
}
}

View File

@@ -2630,7 +2630,7 @@ PLATFORM_ORCHESTRATION_JS = """
}
return sxRenderWithEnv(source, merged);
} catch (e) {
console.warn("sx:route eval error", e);
console.error("[sx-ref] sx:route eval error for:", source, e);
return NIL;
}
}

View File

@@ -389,24 +389,29 @@
(prevent-default e))
;; For GET clicks on links, try client-side routing first
(if (and (= event-name "click")
(= (get verbInfo "method") "GET")
(dom-has-attr? el "href")
(not (get mods "delay"))
(try-client-route (url-pathname (get verbInfo "url"))))
;; Client route succeeded — push state, scroll to top
(do
(browser-push-state (get verbInfo "url"))
(browser-scroll-to 0 0))
;; Fall through to server fetch
(if (get mods "delay")
(let ((is-get-link (and (= event-name "click")
(= (get verbInfo "method") "GET")
(dom-has-attr? el "href")
(not (get mods "delay"))))
(client-routed false))
(when is-get-link
(set! client-routed
(try-client-route (url-pathname (get verbInfo "url")))))
(if client-routed
(do
(clear-timeout timer)
(set! timer
(set-timeout
(fn () (execute-request el verbInfo nil))
(get mods "delay"))))
(execute-request el verbInfo nil))))))
(browser-push-state (get verbInfo "url"))
(browser-scroll-to 0 0))
(do
(when is-get-link
(log-info (str "sx:route server fetch " (get verbInfo "url"))))
(if (get mods "delay")
(do
(clear-timeout timer)
(set! timer
(set-timeout
(fn () (execute-request el verbInfo nil))
(get mods "delay"))))
(execute-request el verbInfo nil))))))))
(if (get mods "once") (dict "once" true) nil))))))