Fix popstate and client routing when no [sx-boost] container exists

handle-popstate falls back to #main-panel when no [sx-boost] element
is found, fixing back button for apps using explicit sx-target attrs.
bindClientRouteClick also checks sx-target on the link itself.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 00:53:08 +00:00
parent ac1dc34dad
commit ece2aa225d
3 changed files with 241 additions and 22 deletions

View File

@@ -829,22 +829,24 @@
(define handle-popstate
(fn (scrollY)
;; Handle browser back/forward navigation.
;; Derive target from the nearest [sx-boost] container.
;; Derive target from [sx-boost] container or fall back to #main-panel.
;; Try client-side route first, fall back to server fetch.
(let ((boost-el (dom-query "[sx-boost]"))
(url (browser-location-href)))
(when boost-el
(let ((target-sel (dom-get-attr boost-el "sx-boost"))
(target (if (and target-sel (not (= target-sel "true")))
(dom-query target-sel)
(let ((url (browser-location-href))
(boost-el (dom-query "[sx-boost]"))
(target-sel (if boost-el
(let ((attr (dom-get-attr boost-el "sx-boost")))
(if (and attr (not (= attr "true"))) attr nil))
nil))
(pathname (url-pathname url)))
(when target
(if (try-client-route pathname target-sel)
(browser-scroll-to 0 scrollY)
(let ((headers (build-request-headers target
(loaded-component-names) _css-hash)))
(fetch-and-restore target url headers scrollY)))))))))
;; Fall back to #main-panel if no sx-boost target
(target-sel (or target-sel "#main-panel"))
(target (dom-query target-sel))
(pathname (url-pathname url)))
(when target
(if (try-client-route pathname target-sel)
(browser-scroll-to 0 scrollY)
(let ((headers (build-request-headers target
(loaded-component-names) _css-hash)))
(fetch-and-restore target url headers scrollY)))))))
;; --------------------------------------------------------------------------