Files
rose-ash/web/request-handler.sx
giles 84a48f0de3 Fix navigation: deep URL routing, back button, render timeout
- request-handler.sx: replace all dots (not just `.(`) and auto-quote
  undefined symbols as strings so 3-level URLs like
  /sx/(geography.(reactive.(examples.counter))) resolve correctly
- sx-platform.js: register popstate handler (was missing from manual
  boot sequence) and fetch full HTML for back/forward navigation
- sx_ref.ml: add CEK step limit (10M steps) checked every 4096 steps
  so runaway renders return 500 instead of blocking the worker forever
- Rename test-runner.sx → runner-placeholder.sx to avoid `test-` skip
- Playwright config: pin testDir, single worker, ignore worktrees

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:54:33 +00:00

76 lines
2.5 KiB
Plaintext

(define
sx-auto-quote
(fn
(expr env)
(cond
(and (symbol? expr) (not (env-has? env (symbol-name expr))))
(symbol-name expr)
(list? expr)
(map (fn (e) (sx-auto-quote e env)) expr)
:else expr)))
(define
sx-expr-to-str
(fn
(expr)
(cond
(string? expr)
(str "\"" expr "\"")
(symbol? expr)
(symbol-name expr)
(list? expr)
(str "(" (join " " (map sx-expr-to-str expr)) ")")
:else (str expr))))
(define
sx-handle-request
(fn
(path headers env)
(let
((is-ajax (or (has-key? headers "sx-request") (has-key? headers "hx-request")))
(raw-sx
(if
(or (= path "/sx/") (= path "/"))
"(home)"
(slice path 4 (len path))))
(page-sx-raw (replace raw-sx "." " "))
(page-exprs (sx-parse page-sx-raw))
(page-expr (if (empty? page-exprs) nil (first page-exprs)))
(page-sx
(if
(nil? page-expr)
page-sx-raw
(sx-expr-to-str (sx-auto-quote page-expr env))))
(layout-sx (str "(~layouts/doc :path \"" path "\" " page-sx ")")))
(if
is-ajax
(let
((full-sx (render-to-sx (first (sx-parse layout-sx)) env)))
full-sx)
(let
((body-html (render-to-html (first (sx-parse layout-sx)) env)))
(render-to-html
(quasiquote
(~shared:shell/sx-page-shell
:title "sx"
:csrf ""
:page-sx (unquote layout-sx)
:body-html (unquote body-html)
:component-defs (unquote (env-get env "__shell-component-defs"))
:component-hash (unquote (env-get env "__shell-component-hash"))
:pages-sx (unquote (env-get env "__shell-pages-sx"))
:sx-css (unquote (env-get env "__shell-sx-css"))
:sx-css-classes (unquote (env-get env "__shell-sx-css-classes"))
:asset-url (unquote (env-get env "__shell-asset-url"))
:sx-js-hash (unquote (env-get env "__shell-sx-js-hash"))
:body-js-hash (unquote (env-get env "__shell-body-js-hash"))
:wasm-hash (unquote (env-get env "__shell-wasm-hash"))
:head-scripts nil
:body-scripts nil
:inline-css nil
:inline-head-js nil
:init-sx nil
:use-wasm true
:meta-html ""))
env))))))