Add console logging for client-side routing decisions

tryClientRoute now logs why it falls through: has-data, no content,
eval failed, or #main-panel not found. tryEvalContent logs the actual
error on catch. Added logWarn platform function (console.warn).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 20:43:27 +00:00
parent f70861c175
commit 2d5096be6c
3 changed files with 19 additions and 8 deletions

View File

@@ -497,6 +497,7 @@ class JSEmitter:
"store-env-attr": "storeEnvAttr",
"to-kebab": "toKebab",
"log-info": "logInfo",
"log-warn": "logWarn",
"log-parse-error": "logParseError",
"parse-and-load-style-dict": "parseAndLoadStyleDict",
"_page-routes": "_pageRoutes",
@@ -2625,6 +2626,7 @@ PLATFORM_ORCHESTRATION_JS = """
}
return sxRenderWithEnv(source, merged);
} catch (e) {
console.warn("sx:route eval error", e);
return NIL;
}
}
@@ -2974,6 +2976,10 @@ PLATFORM_BOOT_JS = """
if (typeof console !== "undefined") console.log("[sx-ref] " + msg);
}
function logWarn(msg) {
if (typeof console !== "undefined") console.warn("[sx-ref] " + msg);
}
function logParseError(label, text, err) {
if (typeof console === "undefined") return;
var msg = err && err.message ? err.message : String(err);

View File

@@ -545,19 +545,19 @@
(if (nil? match)
false
(if (get match "has-data")
false
(do (log-info (str "sx:route server (has data) " pathname)) false)
(let ((content-src (get match "content"))
(closure (or (get match "closure") {}))
(params (get match "params")))
(if (or (nil? content-src) (empty? content-src))
false
(do (log-warn (str "sx:route no content for " pathname)) false)
(let ((env (merge closure params))
(rendered (try-eval-content content-src env)))
(if (nil? rendered)
false
(do (log-warn (str "sx:route eval failed for " pathname)) false)
(let ((target (dom-query-by-id "main-panel")))
(if (nil? target)
false
(do (log-warn "sx:route #main-panel not found") false)
(do
(dom-set-text-content target "")
(dom-append target rendered)