Skip to content

Commit 2644ad9

Browse files
committed
refactor: remove server-side root fallback in router to prevent double-rendering during initial hash resolution
1 parent 5614708 commit 2644ad9

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

‎htag/router.py‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,12 @@ def on_mount(self) -> None:
102102
# We use a name that htag_event will match
103103
self["oninit_route"] = self._on_init_route
104104

105-
# Ask the browser for the current hash after a small delay to ensure
106-
# the client-side bridge is fully ready.
105+
# Ask the browser for the current hash to resolve the initial route.
106+
# The JS round-trip is the single source of truth — no server-side
107+
# fallback to avoid double-rendering when the hash is not "/".
107108
self.call_js(
108109
f"setTimeout(() => htag_event('{self.id}', 'init_route', {{hash: window.location.hash}}), 50)"
109110
)
110-
111-
# Immediate fallback to root if nothing is displayed yet
112-
if not self.childs and self._routes:
113-
# Try to match "/" immediately if available
114-
self._navigate_to("/")
115111

116112
def _on_init_route(self, event: Any) -> None:
117113
"""Handle the initial hash value sent from the browser."""

0 commit comments

Comments
 (0)