hyperfiddle

oλv 2025-10-21T18:27:59.829379Z

Can l/local or l/single be used for evaluating client-side Electric Clojure with dependencies like dom3 and other Electric Clojure namespaces? I was able to use it for evaluating basic Electric Clojure code, but hit errors when trying to use dom/text.

oλv 2025-10-24T13:14:00.761049Z

Sorry for the unclear question 😅 I don't mean to report an issue, but rather ask about what [hyperfiddle.electric-local-def3 :as l] can do. I'm looking at the usage in https://github.com/hyperfiddle/electric/blob/85bbbbc2f27fe84452bbfc68db2771f3323214c3/test/hyperfiddle/electric3_test.cljc#L34 and from that it seems like l/single allows for evaluating Electric Clojure outside of an e/fn. For example, in one of the tests we're invoking an Electric function:

(tests "reactive fn"
       (with ((l/single {} (tap ($ (e/fn [x] (inc x)) 1))) tap tap)
         % := 2))
I was curious whether it is possible to use this l/single macro for running Electric Clojure code that renders to the dom using the dom3 namespace. I think it's not possible, or I am doing it wrong. A code concrete code example is this:
(ns electric-starter-app.main
  (:require [hyperfiddle.electric3 :as e]
            [hyperfiddle.electric-dom3 :as dom]
            [hyperfiddle.electric-local-def3 :as l]))

#?(:cljs
   (defn invoke-hello [node]
     ((l/local {}
               (binding [dom/node node]
                 (dom/text "hello world"))) prn prn)))

(e/defn Main [ring-request]
  (e/client
    (binding [dom/node js/document.body] ; DOM nodes will mount under this one
      (dom/div ; mandatory wrapper div to ensure node ordering - 

        (invoke-hello dom/node)))))

(defn electric-boot [ring-request]
  #?(:clj  (e/boot-server {} Main (e/server ring-request))  ; inject server-only ring-request
     :cljs (e/boot-client {} Main (e/server (e/amb)))))     ; symmetric – same arity – no-value hole in place of server-only ring-request
I was expecting invoke-hello to render "hello world" to the div, but that doesn't happen. Instead I got an error in console:
#object[Error Error: Assert failed: (identical? (r/frame-peer (r/tag-frame tag)) (aget state slot-peer))]

👀 1
oλv 2025-10-24T13:18:07.678999Z

And the https://xyproblem.info/ is, I want to ~eval Electric code without writing to the file system. I tried to evaluate one-sited Electric code which renders to the dom, using l/single , but I wasn't able to 😄

Dustin Getz (Hyperfiddle) 2025-10-24T13:21:42.629859Z

l/local is an electric entrypoint, in the above snippet you are calling it from inside an electric program, that is not a coherent program

👍 1
Dustin Getz (Hyperfiddle) 2025-10-24T13:24:22.633419Z

If there is a problem that prevents electric-dom3 from being used from a test entrypoint, I am not aware of it

oλv 2025-10-24T13:25:49.792269Z

Oh, I'm sure it's possible from a test entrypoint. I haven't tried that. I think I'm just using hyperfiddle.electric-local-def3 wrong. Thanks for taking a look :^)

Dustin Getz (Hyperfiddle) 2025-10-24T13:26:45.117419Z

try calling invoke-hello from the cljs repl

Dustin Getz (Hyperfiddle) 2025-10-24T13:27:31.951519Z

use js/document.querySelector to grab a pre-existing DOM element, you can put it there out of band

xificurC 2025-10-24T13:30:14.918239Z

> I want to ~eval Electric code without writing to the file system Like user input? Sounds like you need an interpreter, we don't have that. And on cljs side it's even harder

👍 1
oλv 2025-10-24T13:40:49.127739Z

[(.-mydiv js/window) (electric-starter-app.main/invoke-hello (.-mydiv js/window))] resulted in [#object[HTMLDivElement [object HTMLDivElement]] #object[missionary.impl.RaceJoin.Process]], but it didn't change #mydiv. Anyways, I have my answer now. Thanks for your time :^)

Dustin Getz (Hyperfiddle) 2025-10-24T14:18:18.070739Z

I dont understand why it didn't write to the #mydiv textnode, i am surprised

Dustin Getz (Hyperfiddle) 2025-10-22T11:30:36.106579Z

your issue report is currently in the "something doesn't work" category of reports that is difficult and time consuming to answer, can you please provide a lot more clarity

👍 1
👍🏻 1
Dustin Getz (Hyperfiddle) 2025-10-22T11:31:02.911199Z

"expected: actual:" for example