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:
@@ -2616,9 +2616,12 @@ PLATFORM_ORCHESTRATION_JS = """
|
||||
link.addEventListener("click", function(e) {
|
||||
e.preventDefault();
|
||||
var pathname = urlPathname(href);
|
||||
// Find the sx-boost target selector from the link's ancestor
|
||||
// Find target selector: sx-boost ancestor, explicit sx-target, or #main-panel
|
||||
var boostEl = link.closest("[sx-boost]");
|
||||
var targetSel = boostEl ? boostEl.getAttribute("sx-boost") : null;
|
||||
if (!targetSel || targetSel === "true") {
|
||||
targetSel = link.getAttribute("sx-target") || "#main-panel";
|
||||
}
|
||||
if (tryClientRoute(pathname, targetSel)) {
|
||||
try { history.pushState({ sxUrl: href, scrollY: window.scrollY }, "", href); } catch (err) {}
|
||||
if (typeof window !== "undefined") window.scrollTo(0, 0);
|
||||
|
||||
@@ -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)))))))
|
||||
|
||||
|
||||
;; --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user