Fork me on GitHub
#hyperfiddle
<
2023-04-22
>
braai engineer08:04:48

Has anyone done any work on deploying the https://github.com/hyperfiddle/electric-xtdb-starter to http://Fly.io? Right now, doesn’t have to scale to multiple regions, but would be nice if one region was the “master” node that others connected to and sync’ed up somehow. I just need to deploy my tax tool with persistent DB so my tax accountants can help categorize/flag expenses… and so it’s no longer tied to my machine.

braai engineer10:04:17

Reactor complains about URL fragment in websocket URL on page reload e.g. localhost:8080/#home or localhost:8080/#/home`. Fragment should probably be stripped from the Websocket URL here: https://github.com/hyperfiddle/electric/blob/0bc5f4bcd96b632f4522de328af66b44f1220fe4/src/hyperfiddle/electric_client.cljs#L31 (this is useful and common for routing memory or sharing links to certain areas of app)

xificurC13:04:11

How did a fragment end up in the electric websocket URL?

Geoffrey Gaillard16:04:12

We forgot to filter it in server-url on line 11.

Dustin Getz14:05:25

I logged a ticket

braai engineer18:04:20

Hmm, I have a route dispatcher in my top-level e/fn, but changing routes is surprisingly slow so I tried to “cache” the views (or signals?) because I know the most common views I want to render, but I see that calling new seems to inject a view in the wrong place or order?

(e/defn Link [!route route-key title]
  (let [current-route (e/watch !route)]
    (dom/a
      (dom/props {
                  ;:href  (str "#" route-key)
                  :class (dom/class-str ["link" (if (= route-key current-route) "active")])})
      (dom/on "click" (e/fn [_] (reset! !route route-key)))
      (dom/text title))))

(e/defn Nav [!route]
  (dom/div
    ;(dom/text "current:route:" (e/watch !route))
    (Link. !route :home "Transactions")
    (Link. !route :404 "Somewhere Else")))

(e/defn DefaultView [!route]
  (e/client
    (let [route (e/watch !route)]
      (dom/div
        (dom/text "missing page for route: " (pr-str route))))))

(e/defn MyApp [!route]
  (e/client
    (let [!route       (atom :home)
          route        (e/watch !route)
          ;; changing !route is slow, so I thought let me cache the "views" (or signals):
          tx-list      (TxList.)
          default-view (DefaultView. !route)]
      ; Hmm, Unexpectedly things are appearing in the wrong order...
      (dom/div
        (dom/h1
          (dom/text "Test")
          (dom/small
            (Nav. !route)))
        (case route
          :home tx-list
          (DefaultView. !route))))))

braai engineer18:04:55

Btw. would be cool if Electric could add some meta-data to each dom node to show how long it took to render/delete that can be used to color the element background so I can see which nodes in the AST are slow, esp. if they trigger network traffic. Sort of like, “time spent in calculation” to spot hot nodes. cc @U09K620SG

denik20:04:15

e/dom renders by side effect which is why TxList and DefaultView render into the current e/dom node at evaluation time in the let

braai engineer21:04:50

Can it render where I place it? Is there a way to defer the render until I place it somewhere? The reason I want to “cache” the view is because it takes ~2 seconds to change from the TxList (a complex view) to the simple DefaultView. I tested it and it changes quickly between two simple views but takes a long time from the complex view, presumably because it’s doing a bunch of teardown - not sure how to profile it.

Dustin Getz00:04:57

our tear downs are slow with large amounts of dom , this is a known issue that we haven’t looked into yet

Dustin Getz00:04:58

you can defer rendering by wrapping it in e/fn; dom/text has the same evaluation rules as println basically

vincent23:04:09

offhand somebody know the default web socket port?

vincent23:04:32

big fan so far just need to get my dev box cooperatin' then i'll be flyin'! 😄

vincent23:04:15

Okay I had a question about getting the websocket working

Dustin Getz00:04:41

hey i’m out of town this weekend but i would direct you to the starter app repo which should contain a working app. that env var is checked in prod configurations to auto-refresh the page after a rolling deploy

Dustin Getz00:04:53

you can grep the repo (search on github should work) to find that env var and see the exact rules

vincent02:04:01

Thank you, and no rush dude, I appreciate any and all help, whenever is convenient for you.

vincent02:04:16

I will check the repo more.

vincent03:04:56

Dude I am such a goon. There's the line `

HYPERFIDDLE_ELECTRIC_APP_VERSION=`git describe --tags --long --always --dirty
` in the flippin docs I didn't notice that addition. But,I still get the error in the web console, i think because not forwarding web socket port? am invoking with
clj -A:dev -X user/main

vincent03:04:56

Dude I am such a goon. There's the line `

HYPERFIDDLE_ELECTRIC_APP_VERSION=`git describe --tags --long --always --dirty
` in the flippin docs I didn't notice that addition. But,I still get the error in the web console, i think because not forwarding web socket port? am invoking with
clj -A:dev -X user/main