Add component deps to page registry, check before client routing
Each page entry now includes a deps list of component names needed. Client checks all deps are loaded before attempting eval — if any are missing, falls through to server fetch with a clear log message. No bundle bloat: server sends components for the current page only. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -543,24 +543,42 @@
|
||||
;; Client-side routing
|
||||
;; --------------------------------------------------------------------------
|
||||
|
||||
(define has-all-deps?
|
||||
(fn (deps)
|
||||
;; Check if all component deps are loaded in the client env.
|
||||
;; deps is a list of component name strings (e.g. "~essay-foo").
|
||||
(let ((loaded (loaded-component-names))
|
||||
(missing false))
|
||||
(for-each
|
||||
(fn (dep)
|
||||
(when (not (contains? loaded dep))
|
||||
(set! missing dep)))
|
||||
deps)
|
||||
(if missing
|
||||
(do (log-info (str "sx:route missing component " missing)) false)
|
||||
true))))
|
||||
|
||||
(define try-client-route
|
||||
(fn (pathname)
|
||||
;; Try to render a page client-side. Returns true if successful, false otherwise.
|
||||
;; Only works for pages without :data dependencies.
|
||||
;; Only works for pages without :data dependencies and with all deps loaded.
|
||||
(let ((match (find-matching-route pathname _page-routes)))
|
||||
(if (nil? match)
|
||||
(do (log-info (str "sx:route no match (" (len _page-routes) " routes) " pathname)) false)
|
||||
(if (get match "has-data")
|
||||
(do (log-info (str "sx:route server (has data) " pathname)) false)
|
||||
(let ((content-src (get match "content"))
|
||||
(deps (or (get match "deps") (list)))
|
||||
(closure (or (get match "closure") {}))
|
||||
(params (get match "params")))
|
||||
(if (or (nil? content-src) (empty? content-src))
|
||||
(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)
|
||||
(do (log-warn (str "sx:route eval failed for " pathname)) false)
|
||||
(if (not (has-all-deps? deps))
|
||||
(do (log-info (str "sx:route server (missing deps) " pathname)) false)
|
||||
(let ((env (merge closure params))
|
||||
(rendered (try-eval-content content-src env)))
|
||||
(if (nil? rendered)
|
||||
(do (log-warn (str "sx:route eval failed for " pathname)) false)
|
||||
(let ((target (dom-query-by-id "main-panel")))
|
||||
(if (nil? target)
|
||||
(do (log-warn "sx:route #main-panel not found") false)
|
||||
@@ -571,7 +589,7 @@
|
||||
(process-elements target)
|
||||
(sx-hydrate-elements target)
|
||||
(log-info (str "sx:route client " pathname))
|
||||
true))))))))))))
|
||||
true)))))))))))))
|
||||
|
||||
|
||||
(define bind-client-route-link
|
||||
|
||||
Reference in New Issue
Block a user