Fork me on GitHub
#hyperfiddle
<
2023-05-30
>
Amos03:05:47

Hi, I’m looking into the electric starter app. I wonder when exactly the shadow load the app.todo-list. Thanks in advance.

2
Amos00:05:45

Thank you. That helps a lot.

noonian06:05:42

Hello! I am seeing behavior that I don't understand and I am wondering if it could be a bug in electric and/or e/for. In this snippet, my expectation is that no code inside a when block would ever execute when the value of the condition is false, but I see that happen with the code below. I'd appreciate any insight into what is happening here. I am using electric v2-alpha-284-g0bc5f4bc and missionary b.30

(e/defn ComponentWithFor [items]
  (dom/ul
    (e/for [item items]
      (dom/li (dom/text item)))))

(e/defn StrangeBugRepro []
  (let [!x (atom 0)
        x (e/watch !x)]
    ;; When this button is clicked, "x: nil" prints to the console
    (ui4/button (e/fn []
                  (reset! !x nil))
      (dom/text "Reset x to nil"))
    (when x
      ;; This should never print if x is nil... right? It does if...
      (println "x:" x)

      ;; ...there is another electric function call in the
      ;; when that uses e/for and the e/for depends on x. Does not
      ;; occur if e/for is inlined.
      (ComponentWithFor. (range x))
      )))

❤️ 2
xificurC08:05:18

Hey, thanks for the report and the repro! We're aware of a similar issue but it includes a server transfer, while your case involves only involves an e/for. I logged a ticket for this. The internals are going through a major rewrite that might solve this issue, otherwise we'll look into it after the internal rewrite lands. Do you need help finding a workaround for your project? Including a minimal RCF for reference.

👍 4
braai engineer13:05:07

@U052PH695 does the same thing happens when not using the ui4/button helper? E.g. (dom/a (dom/on "click" (e/fn [e] (reset! !x nil) …)) I’ve had similar issues with ui4/button, but may be a different edge case.

yes 2
noonian17:05:26

Thank you, it's helpful to know this is unintended behavior 🙂 I'm excited for the rewrite, and any workarounds in the meantime would be helpful but I can probably live with it for the time being. I'm also happy to help test the new implementation once it's ready for that