Fix <vm:anon> display: move effect to _eff let binding

The effect form returns a VM closure (disposer) which the island DOM
renderer displayed as text. Moving it to a let binding (_eff) captures
the return value without rendering it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 10:25:58 +00:00
parent d938682469
commit eb060ef32c

View File

@@ -1,4 +1,4 @@
;; Pretext island — full version with :ref (bug fix applied) ;; Pretext island — effect as let binding
(defisland (defisland
~pretext-demo/live ~pretext-demo/live
() ()
@@ -10,99 +10,97 @@
(doc (host-global "document")) (doc (host-global "document"))
(canvas (host-call doc "createElement" "canvas")) (canvas (host-call doc "createElement" "canvas"))
(ctx (host-call canvas "getContext" "2d")) (ctx (host-call canvas "getContext" "2d"))
(el-ref (signal nil))) (el-ref (signal nil))
(effect (_eff
(fn (effect
() (fn
(let ()
((el (deref el-ref))
(w (deref mxw))
(sz (deref font-size))
(opt (deref use-optimal)))
(when
el
(let (let
((lh (* sz 1.5))) ((el (deref el-ref))
(host-set! (w (deref mxw))
ctx (sz (deref font-size))
"font" (opt (deref use-optimal)))
(str sz "px 'Pretext Serif', DejaVu Serif, serif")) (when
(let el
((widths (map (fn (wd) (host-get (host-call ctx "measureText" wd) "width")) words)) (host-set!
(spw (host-get (host-call ctx "measureText" " ") "width"))) ctx
"font"
(str sz "px 'Pretext Serif', DejaVu Serif, serif"))
(let (let
((ranges (if opt (break-lines widths spw w) (break-lines-greedy widths spw w))) ((lh (* sz 1.5))
(lines (widths
(pretext-layout-lines (map
words (fn
widths (wd)
(if (host-get (host-call ctx "measureText" wd) "width"))
opt words))
(break-lines widths spw w) (spw
(break-lines-greedy widths spw w)) (host-get (host-call ctx "measureText" " ") "width")))
spw
w
lh)))
(host-set! el "innerHTML" "")
(let (let
((info (host-call doc "createElement" "div"))) ((ranges (if opt (break-lines widths spw w) (break-lines-greedy widths spw w))))
(host-set! info "className" "px-4 pt-3 pb-1")
(host-set!
info
"innerHTML"
(str
"<span class='text-xs font-medium uppercase tracking-wide text-stone-400'>"
(len lines)
" lines — "
w
"px / "
sz
"px / "
(if opt "optimal" "greedy")
"</span>"))
(host-call el "appendChild" info))
(let
((container (host-call doc "createElement" "div")))
(host-set!
container
"style"
(str
"position:relative;height:"
(* (len lines) lh)
"px;padding:12px 16px"))
(let (let
render-lines ((lines (pretext-layout-lines words widths ranges spw w lh))
((li 0)) (info (host-call doc "createElement" "div"))
(when (container (host-call doc "createElement" "div")))
(< li (len lines)) (host-set! el "innerHTML" "")
(let (host-set! info "className" "px-4 pt-3 pb-1")
((line (nth lines li)) (host-set!
(wds (get (nth lines li) :words))) info
"innerHTML"
(str
"<span class='text-xs font-medium uppercase tracking-wide text-stone-400'>"
(len lines)
" lines — "
w
"px / "
sz
"px / "
(if opt "optimal" "greedy")
"</span>"))
(host-call el "appendChild" info)
(host-set!
container
"style"
(str
"position:relative;height:"
(+ (* (len lines) lh) 24)
"px;padding:12px 16px"))
(let
rl
((li 0))
(when
(< li (len lines))
(let (let
render-words ((line (nth lines li))
((wi 0)) (wds (get (nth lines li) :words)))
(when (let
(< wi (len wds)) rw
(let ((wi 0))
((pw (nth wds wi)) (when
(span (< wi (len wds))
(host-call doc "createElement" "span"))) (let
(host-set! span "textContent" (get pw :word)) ((pw (nth wds wi))
(host-set! (span
span (host-call doc "createElement" "span")))
"style" (host-set!
(str span
"position:absolute;left:" "textContent"
(+ (get pw :x) 16) (get pw :word))
"px;top:" (host-set!
(+ (get line :y) 12) span
"px;font:" "style"
sz (str
"px 'Pretext Serif',serif;white-space:nowrap")) "position:absolute;left:"
(host-call container "appendChild" span) (+ (get pw :x) 16)
(render-words (+ wi 1)))))) "px;top:"
(render-lines (+ li 1)))) (+ (get line :y) 12)
(host-call el "appendChild" container))))))))) "px;font:"
sz
"px 'Pretext Serif',serif;white-space:nowrap"))
(host-call container "appendChild" span)
(rw (+ wi 1))))))
(rl (+ li 1))))
(host-call el "appendChild" container))))))))))
(div (div
(~tw :tokens "space-y-4") (~tw :tokens "space-y-4")
(div (div
@@ -144,6 +142,6 @@
:on-click (fn (e) (reset! use-optimal (not (deref use-optimal)))) :on-click (fn (e) (reset! use-optimal (not (deref use-optimal))))
(if (deref use-optimal) "Knuth-Plass" "Greedy")))) (if (deref use-optimal) "Knuth-Plass" "Greedy"))))
(div (div
:class "rounded-lg border border-stone-200 bg-white overflow-hidden" :class "rounded-lg border border-stone-200 bg-white"
:ref (fn (el) (reset! el-ref el)) :ref (fn (el) (reset! el-ref el))
"")))) ""))))