From 1320e8bcc3436d7b7dfb53f1b645b1af9929e689 Mon Sep 17 00:00:00 2001 From: Martin Kavalar Date: Wed, 27 Sep 2023 14:42:00 +0200 Subject: [PATCH] Fix inspect --- src/nextjournal/clerk/render.cljs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nextjournal/clerk/render.cljs b/src/nextjournal/clerk/render.cljs index ec5091f29..2bbfd99fc 100644 --- a/src/nextjournal/clerk/render.cljs +++ b/src/nextjournal/clerk/render.cljs @@ -535,6 +535,14 @@ (:nextjournal/render-opts x) {:viewer viewer :path path})])))) + +;; TODO: figure out if we can make `inspect` work synchronously by +;; evaluating the `:render-fn`s on init to fix the flicker +(declare await-render-fns) +(defn await+inspect-presented [x] + (when-let [desc (hooks/use-promise (await-render-fns x))] + [inspect-presented desc])) + (defn inspect [value] (r/with-let [!state (r/atom nil)] (when (not= (:value @!state ::not-found) value) @@ -546,7 +554,7 @@ (.resolve js/Promise (present-elision-fn fetch-opts))) (fn [more] (swap! !state update :desc viewer/merge-presentations more fetch-opts))))} - [inspect-presented (:desc @!state)]])) + [await+inspect-presented (:desc @!state)]])) (defn show-panel [panel-id panel] (swap! !panels assoc panel-id panel))