From 2a978e6e9fc9fb402033516d340a0f5df1cd29bb Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 6 Mar 2026 21:44:55 +0000 Subject: [PATCH] Add explicit logging for route decisions in bind-event - Log "sx:route server fetch " 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 --- shared/static/scripts/sx-browser.js | 13 +++++++--- shared/sx/ref/bootstrap_js.py | 2 +- shared/sx/ref/orchestration.sx | 39 ++++++++++++++++------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/shared/static/scripts/sx-browser.js b/shared/static/scripts/sx-browser.js index d47e629..6235668 100644 --- a/shared/static/scripts/sx-browser.js +++ b/shared/static/scripts/sx-browser.js @@ -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; } } diff --git a/shared/sx/ref/bootstrap_js.py b/shared/sx/ref/bootstrap_js.py index f39c979..ba1fea8 100644 --- a/shared/sx/ref/bootstrap_js.py +++ b/shared/sx/ref/bootstrap_js.py @@ -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; } } diff --git a/shared/sx/ref/orchestration.sx b/shared/sx/ref/orchestration.sx index a8fa6f5..cafe2db 100644 --- a/shared/sx/ref/orchestration.sx +++ b/shared/sx/ref/orchestration.sx @@ -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))))))