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

@@ -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);