This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-03
Channels
- # announcements (15)
- # babashka (143)
- # babashka-sci-dev (2)
- # beginners (35)
- # biff (11)
- # calva (5)
- # cider (8)
- # clerk (4)
- # clj-kondo (58)
- # cljdoc (6)
- # clojure (88)
- # clojure-denmark (1)
- # clojure-europe (77)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-uk (1)
- # clojurescript (19)
- # clr (32)
- # code-reviews (158)
- # datahike (5)
- # datomic (10)
- # deps-new (3)
- # fulcro (12)
- # graalvm (20)
- # honeysql (23)
- # hyperfiddle (32)
- # kaocha (17)
- # membrane (6)
- # observability (1)
- # other-languages (2)
- # pathom (5)
- # practicalli (12)
- # reagent (4)
- # reitit (7)
- # releases (1)
- # sci (25)
- # shadow-cljs (52)
Hi guys! Is this a valid mount (`on-mount`) operation: (e/server (e/offload #(do something))
? Here (https://gist.github.com/jeans11/c758a40842b30b11c1e324c99ab39620) when a client goes into an Item
the List
of the other client is updated indefinitely. Maybe the mount operation is not in the right place? I’m missing something :thinking_face:
what line
does it happen when someone clicks?
i need more info
also are you running latest? (v2-alpha-123)
(e/server (e/offload #(update-item-visits item-eid (:user state))) nil)
this is transacting during render, is that what you intend?
It might be infinite looping (transacting your db in a tight loop)
no, i dont see how it could be looping actually
I’m not yet on the latest version. Sorry for the missing information. Yes this is the line. When someone click on an item the list of an other client start an infinite loop.
Please first try v2-123, and then if that doesn't work can you minimize it down to something I can run? instead of transact try swapping an atom
I tested with the last release and with a simple atom. It works perfectly. But with a db like datascript
or datalevin
this happen:
(PS: without e/offload
on each server call, there is no problem)
Ok, this is a known issue that we know how to fix, we hope to start tomorrow
Can you just remove the e/offload call for now?
Also @UHZPYLPU1 can i see the exact source code for that video
Hi @U09K620SG, thanks for your answer. The source code of that video is available here https://gist.github.com/jeans11/c758a40842b30b11c1e324c99ab39620
Related to the e/offload
issue, I notice an unexpected behaviour of e/on-unmount
with the presence of an e/offload
in a component (maybe because I try with no catch Pending
). It seems that e/on-unmount
is directly call when the component is rendering.
:item/visits [n]
looks fishy. It should be a single number, not sure what this will do, probably since you marked it card-many and n
is always nil
it'll have many [nil]
s in the db. Does datalevin support transaction functions? You need an atomic increment, so either a CAS operator, a transaction function, or use https://cljdoc.org/d/datalevin/datalevin/0.8.5/api/datalevin.core#with-transaction
e/on-unmount
will only run when your component is unmounting. Can you show your code?
> :item/visits [n]
looks fishy. It should be a single number, not sure what this will do, probably since you marked it card-many and n
is always nil
it’ll have many [nil]
s in the db. Does datalevin support transaction functions? You need an atomic increment, so either a CAS operator, a transaction function, or use https://cljdoc.org/d/datalevin/datalevin/0.8.5/api/datalevin.core#with-transaction
Hi @U09FL65DK thanks for you message. Sorry the item/visits
is not explicit. It store the id of the current user. When a user comes into an Item
his id is added into the item/visits
array.
> e/on-unmount
will only run when your component is unmounting. Can you show your code?
I made a revision here https://gist.github.com/jeans11/c758a40842b30b11c1e324c99ab39620 to add the e/on-unmount
.
(e/on-unmount #(do (prn "FOO") (retract-item-visits item-eid (:user state))))
In fact, the (prn "FOO")
is print when the component is rendering (cf. screencast).
re item/visits: I see. In that case I think the vector wrapping isn't needed, you should be able to just transact n
directly
re on-unmount: can you try putting it on the client with just the (prn "FOO")
? I.e. move it out of the server block
> you should be able to just transact n
directly
You right!
> can you try putting it on the client with just the (prn "FOO")
? I.e. move it out of the server block
I put (e/on-unmount #(prn "FOO")))
directly in the client and it works as expected.
I think what's happening is
• your update-item-visits
call runs on render and it transacts
• this triggers a new db
value
• now item
on line 75 is re-run, throwing Pending first
• this makes item-eid
Pending too
• item-eid
is inside the on-unmount call, so it also throws, therefore unmounts
you could try a refactor where Item
already takes the item-eid
as an argument. Resolve it on the server, without any offloads so it'll never be pending
something like
(Item. !state state (d/q '[:find ?e . :in $ ?id :where [?e :item/id ?id]] db (:id state)))
@U09FL65DK thanks for your explanation (very helpfull). It will be great, indeed, to have a guide
of this.
@UHZPYLPU1 is this resolved?
Hi @U09K620SG yes, it’s ok!