nextjournal / clerk

⚡️ Moldable Live Programming for Clojure
https://clerk.vision
ISC License
1.74k stars 75 forks source link

Clerk cannot render nested wrapped values #639

Closed zampino closed 2 months ago

zampino commented 3 months ago
;; # 🐞Debug
(ns scratch.debug
  {:nextjournal.clerk/visibility {:code :hide}}
  (:require [nextjournal.clerk :as clerk]
            [nextjournal.clerk.viewer :as viewer]))

{:nextjournal/value (clerk/with-viewer viewer/string-viewer "hello")}

the above gives:

CleanShot 2024-03-25 at 15 34 27@2x

This is the cause of https://github.com/nextjournal/clerk/issues/638#issuecomment-2018168649.

zampino commented 3 months ago

The error depends also on which values are being wrapped: CleanShot 2024-03-25 at 16 40 06@2x

zampino commented 3 months ago

I believe the reason for this is how viewer/present treats wrapped values:


[(viewer/present {:nextjournal/value (clerk/with-viewer viewer/string-viewer "hello")})
 (viewer/present {:nextjournal/value (clerk/with-viewer viewer/number-viewer 123)})]

;; => [{:path [],
;;      :nextjournal/value "hello",
;;      :nextjournal/viewer {:name nextjournal.clerk.viewer/map-viewer,
;;                           :render-fn #viewer-fnnextjournal.clerk.render/render-map,
;;                           :opening-paren "{",
;;                           :closing-paren ("}"),
;;                           :page-size 10,
;;                           :hash "5drSiYgxwbGAGQx15hZm4Ts9vK16be"}}
;;     {:path [],
;;      :nextjournal/value 123,
;;      :nextjournal/viewer {:name nextjournal.clerk.viewer/map-viewer,
;;                           :render-fn #viewer-fnnextjournal.clerk.render/render-map,
;;                           :opening-paren "{",
;;                           :closing-paren ("}"),
;;                           :page-size 10,
;;                           :hash "5drSiYgxwbGAGQx15hZm4Ts9vK16be"}}]

the inner value and the assigned viewer definitely go out of sync.