Skip to content

Commit 6440baa

Browse files
authored
Fix advanced compilation issue with history navigation (#462)
1 parent ac409d1 commit 6440baa

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/nextjournal/clerk/render.cljs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@
140140

141141
(declare clerk-eval)
142142

143-
(defn ->URL [href]
143+
(defn ->URL [^js href]
144144
(js/URL. href))
145145

146146
(defn handle-anchor-click [^js e]
147-
(prn :handle-anchor-click e)
148147
(when-some [url (some-> e .-target closest-anchor-parent .-href ->URL)]
149148
(when (= (.-search url) "?clerk/show!")
150149
(.preventDefault e)
@@ -153,18 +152,14 @@
153152
(seq (.-hash url))
154153
(assoc :fragment (subs (.-hash url) 1))))))))
155154

156-
(defn history-push-state [{:keys [path fragment replace?]}]
157-
(when (not= path (some-> js/history .-state .-clerk_show))
158-
(j/call js/history
159-
(if replace? :replaceState :pushState)
160-
#js {:clerk_show path} nil (str "/" path (when fragment (str "#" fragment))))))
155+
(defn history-push-state [{:as opts :keys [path fragment replace?]}]
156+
(when (not= path (some-> js/history .-state .-path))
157+
(j/call js/history (if replace? :replaceState :pushState) (clj->js opts) "" (str "/" path (when fragment (str "#" fragment)))) ))
161158

162159
(defn handle-history-popstate [^js e]
163-
(prn :handle-history-popstate e)
164-
(when-some [notebook-path (some-> e .-state .-clerk_show)]
160+
(when-let [{:as opts :keys [path]} (js->clj (.-state e) :keywordize-keys true)]
165161
(.preventDefault e)
166-
(clerk-eval (list 'nextjournal.clerk.webserver/navigate! {:nav-path notebook-path
167-
:skip-history? true}))))
162+
(clerk-eval (list 'nextjournal.clerk.webserver/navigate! {:nav-path path :skip-history? true}))))
168163

169164
(defn render-notebook [{:as _doc xs :blocks :keys [bundle? css-class sidenotes? toc toc-visibility header footer]} opts]
170165
(r/with-let [local-storage-key "clerk-navbar"

0 commit comments

Comments
 (0)