hyperfiddle

Andrew Wilcox 2025-06-12T04:04:45.657899Z

Is this an OK way to cause the input to render first?

(let [foo (dom/input
                (dom/On "input" (fn [event] (-> event .-target .-value)) ""))]
      ((fn [_]) foo)
      (dom/div (dom/text "between"))
      (dom/div (dom/text "foo: " foo)))
I've also seen the suggestion here to use case to force the evaluation order, is there something different that using case would do, or is using case simply idiomatic?

xificurC 2025-06-12T08:04:30.617999Z

just foo is enough instead of ((fn [_]) foo)

馃憤 1
Andrew Wilcox 2025-06-13T02:31:57.863099Z

(defmacro eager [v x & body]
  `(let [~v ~x]
     ~v
     ~@body))
(not suitable for destructuring)

Andrew Wilcox 2025-06-13T03:31:48.208879Z

I'm intrigued that this is possible

(defmacro eager [v x & body]
  (if (symbol? v)
    ;; simple, non-destructuring version
    `(let [~v ~x]
       ~v
       ~@body)

    ;; destructuring version
    `(let [value# ~x
           ~v value#]
       value#
       ~@body)))

(defmacro do1 [expr & rest]
  "Sequence like `do`, but return the value of the first expression."
  `(let [value# ~expr]
     value#
     ~@rest
     value#))

(e/defn Summary-Detail [Summary Detail]
  (dom/div (dom/props {:class "flex flex-col"})
    (eager expanded
      (dom/div (dom/props {:class "flex flex-row"})
        (do1
          (dom/div
            (dom/props {:class "w-6 pl-1"})
            (Expanded-Icon))
          (dom/div
            (Summary))))
      (when expanded
        (dom/div (dom/props {:class "flex flex-row"})
          (dom/div (dom/props {:class "w-6"}))
          (dom/div
            (Detail)))))))
Expanded-Icon displays a rightward pointing caret and returns false; clicking the caret changes it to a downward pointing caret and then Expanded-Icon returns true. Summary-Detail initially displays the summary, and then if you click the caret it also displays the detail. I suppose in this particular example it might be simpler to use an atom for the state at the top of the function and then not need to thread the expanded true/false up through the UI elements... but, intrigued. (We can't do this in React!)

xificurC 2025-06-13T06:30:23.384609Z

right, it's just functions 馃槈

braai engineer 2025-06-12T07:56:04.025499Z

Hi Guys, any idea why am I not seeing log output in this Electric component, even when log/debug is called from a Clojure function? I can see logs in another component where I'm running a normal Clojure function that calls log/debug, but for some reason, not when calling a Clojure fn that logs, from this component. The reason I'm trying to emit logs is because when I navigate to the 3rd page via pagination, Electric client crashes w/o logs.

xificurC 2025-06-12T08:07:30.204289Z

let bindings are lazy, they won't run unless used. (let [_ (prn 'foo)]) will never print foo. Put the debug prints in a do (e.g. in the let body)

braai engineer 2025-06-12T08:08:00.388389Z

ah, but won't they run if a value is passed that changed?

xificurC 2025-06-12T08:08:28.436259Z

if the binding (in this case _) isn't used somewhere, no

braai engineer 2025-06-12T08:08:48.552849Z

ahhh, so it's about the left-side binding

braai engineer 2025-06-12T08:09:08.132439Z

I would have expected it to run if the right-side touches a symbol that changed

xificurC 2025-06-12T08:09:18.208399Z

yes, let basically compiles to a missionary signal. The signal won't be sampled unless used

鉂わ笍 1
braai engineer 2025-06-12T08:09:22.762169Z

thx this fixes a big misunderstanding I had

braai engineer 2025-06-12T08:34:36.349079Z

(deleted snippet to not pollute channel - same component is incluced as snippet in next message on new thread)

braai engineer 2025-06-12T08:34:07.037589Z

I'm trying to render a paginated list of accounts which are the result of d/q + (pull ?account [*]). It works when the (e/for [account diffed-accounts] ...) runs in e/client, but crashes on the *3rd page* of pagination only when e/for is under e/server, despite (e/server (pr-str account)) running on server in both cases. At first I thought I was trying to render something unserializable that only appeared on the 3rd page, but it's just a collection of maps. So I reduced the page size to 10, reversed the collection before diffing and also tried diffing on different keys: it always crashes on the 3rd page, no matter what. Am I doing something wrong here? The log output is displayed on server REPL before the crash, and looks normal (note: :entity/id is a string, not a UUID):

... ; ~500 preceding items
DEBUG electric-starter-app.main: debug {:db/id 17592186170221, :resource/type :account, :entity/id 684a8b53-803e-41c6-a623-7753eaf1dd1e}
DEBUG electric-starter-app.main: debug {:db/id 17592186218736, :resource/type :account, :entity/id 684a8b55-a9d8-4745-b8b4-c7aa9263fff1}

braai engineer 2025-06-20T08:13:49.473709Z

@dustingetz in meantime until I can make smaller example, if you wrap https://github.com/theronic/eacl-electric-starter-app/blob/main/src/electric_starter_app/main.cljc#L393`e/for`https://github.com/theronic/eacl-electric-starter-app/blob/main/src/electric_starter_app/main.cljc#L393 in e/server, you should be able to replicate the crash. it seems to render the first time but fails on 3rd re-render, which implies a potential diffing issue 1. wrap the e/for in e/server 2. click Next Page twice (regardless of page size) 3. reactor crashes.

braai engineer 2025-06-20T14:20:07.354879Z

Here is https://github.com/theronic/electric-efor-bug-repro/blob/main/src/electric_starter_app/main.cljc of e/for crashing Electric inside an e/server (but not e/client) when looping over 1k plain maps that are sorted and paginated. Was forked from v3 starter app (no Datomic, no EACL, no Mount). Also fails if you click Next Page button followed by Prev Page button.

馃憖 2
braai engineer 2025-06-19T20:56:14.992919Z

I鈥檓 compelled to say this is an e/for bug in Electric. Same bug bit me in another project today: Reactor crashes with no recourse. Have to restart REPL to recover and no error logs. Solved by taking e/for out of e/server and running on e/client. Will reproduce minimal example and share.

馃檹 1
braai engineer 2025-06-12T08:36:19.275519Z

1st & 2nd pages look like this, 3rd page is blank (client crash)

xificurC 2025-06-12T11:19:41.772809Z

nothing jumps out as immediately wrong on a quick skim. I'd try minimizing the breaking example by commenting out parts of it

Dustin Getz (Hyperfiddle) 2025-06-12T21:40:25.613749Z

we will fix it but we need a way to reproduce it, this example is not self contained

Dustin Getz (Hyperfiddle) 2025-06-12T21:41:21.783559Z

if you give us a qry-accounts with mock data (inine the actual data as edn) and it still crashes, that might be enough

Dustin Getz (Hyperfiddle) 2025-06-12T21:42:50.374969Z

try moving the log to after the e/for, because electric is concurrent and is probably running those expressions in reverse, i.e., you see the log for the record before the record that crashed (if it is the record which is bad)

Dustin Getz (Hyperfiddle) 2025-06-12T21:43:16.366019Z

i know you said the order seems not to matter, but still the diff-by is a likely culprit

Noah Shepard 2025-06-12T17:58:33.833779Z

may I ask for some super-beginner help? I'm trying to modify the most recent electric-starter-app. I added re-graph (https://github.com/oliyh/re-graph) to the deps.edn. I run the command line dev build from the readme "clj -A:dev -X dev/-main"

o位v 2025-06-12T18:20:29.011459Z

Hello 馃槃 Reagent expects you to install React: https://github.com/reagent-project/reagent?tab=readme-ov-file#usage re-graph describes itself as "GraphQL client for re-frame applications", you might want to try using a GraphQL client which isn't coupled to another ClojureScript framework? In any case this is probably a better question for #beginners or #clojurescript

Noah Shepard 2025-06-12T18:22:33.952269Z

ok - thanks - I considered starting there, but thought it might be specific to electric, as re-graph has worked fine for me in regular (not clojurescript) projects in the past

o位v 2025-06-12T18:28:59.055809Z

In these projects you presumably had react installed already?

Noah Shepard 2025-06-12T18:30:11.560499Z

I dont think so - and I think I may have figured out my issue - I found some :require entries (in dev.cljc) that are prefixed with "#?(:clj" - copying that (macro invocation?) in my electric component with re-graph gets me past the build error!

o位v 2025-06-12T18:32:35.596659Z

I think you're treating the symptom not the problem now :^)

o位v 2025-06-12T18:33:17.225979Z

Wrapping in #?(:clj ...) makes it so that the wrapped form is only read (and evaluated) on JVM Clojure.

Noah Shepard 2025-06-12T18:33:47.638919Z

could be! (and thanks for the help btw). re-graph says its "Clojure/Clojurescript" so I guess I thought it was a package that could be build (perhaps with different feature-sets?) in either context

Noah Shepard 2025-06-12T18:34:03.517019Z

but again, I am way out of my depth here

o位v 2025-06-12T18:34:04.135249Z

Oh, right I missed that

o位v 2025-06-12T18:34:57.889499Z

So if you do #?(:clj (:require [re-graph.core])) you should be able to use it on the JVM side no problem

o位v 2025-06-12T18:35:24.443829Z

https://clojure.org/guides/reader_conditionals

馃憖 1
o位v 2025-06-12T18:35:50.734639Z

No problem 馃槃

Noah Shepard 2025-06-12T18:35:53.940749Z

ok, awesome, I've yet to make the call, but its nice to know that I could reasonably expect it to work 馃檪 (on the jvm side)

馃憤 1
Noah Shepard 2025-06-12T23:18:35.526829Z

may I ask another question? would I be right in thinking that I cannot call an electric function within e/Offload ?

Noah Shepard 2025-06-12T23:19:04.640029Z

(that is to say, I get a macroexpand error when I do this)

o位v 2025-06-12T23:33:09.345519Z

Correct

Noah Shepard 2025-06-12T17:59:00.580529Z

I get a compile failure, in which namespace react is required, but not found - react is a dep of re-graph

Noah Shepard 2025-06-12T17:59:21.253679Z

I'm very new to Clojure in general - is there some 'pre-build step' I'm missing?

Noah Shepard 2025-06-12T18:03:13.743239Z

the exact error: The required namespace "react" is not available, it was required by "reagent/core.cljs".

braai engineer 2025-06-12T21:38:47.682419Z

Reporting because the error says, "please report this." Persists after restarting REPL and restarting (dev/-main). Happened after adding a new component which is copy of an existing (working) component with slightly different query values and adding it to entrypoint. If I wrap the component in (when false (Component)), it does not crash.

braai engineer 2025-06-12T21:51:37.894599Z

found issue: caused by an error in a function running in (e/Offload #(...))

Geoffrey Gaillard 2025-06-13T04:54:17.547719Z

Thank you for the report 馃憤