This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-21
Channels
- # announcements (51)
- # asami (5)
- # babashka (25)
- # babashka-sci-dev (26)
- # beginners (33)
- # calva (10)
- # clj-kondo (51)
- # clj-yaml (99)
- # clojure (96)
- # clojure-australia (3)
- # clojure-berlin (5)
- # clojure-europe (151)
- # clojure-norway (58)
- # clojurescript (20)
- # cursive (13)
- # datalevin (1)
- # datomic (19)
- # docker (6)
- # emacs (55)
- # events (1)
- # fulcro (50)
- # gratitude (8)
- # juxt (7)
- # leiningen (5)
- # malli (6)
- # membrane (1)
- # nbb (28)
- # off-topic (22)
- # pathom (7)
- # polylith (20)
- # portal (1)
- # reagent (37)
- # reitit (2)
- # releases (2)
- # reveal (32)
- # scittle (34)
- # shadow-cljs (46)
- # testing (10)
- # tools-deps (33)
- # xtdb (18)
I have a report with a custom ro/BodyItem
. When I route to it the report for the first time, the rows are correct. If I then go back and select another related report, the rows do not update from the previous visit to. If I go back again and select a third related report, the rows from the second report appear in it. And so it lags behind one like this each time. All the while, the data in the db as well as the props of the BodyItem are correct.
I've tried to use the troubleshooting tree to figure it out. The db->tree result looks correct to me.
The only errors I'm seeing in the console are:
react_devtools_backend.js:4026 WARN [com.fulcrologic.fulcro.ui-state-machines:691] - UNEXPECTED EVENT: Did not find a way to handle event :ready! in the current active state: :routed See
react_devtools_backend.js:4026 WARN [com.fulcrologic.fulcro.ui-state-machines:691] - UNEXPECTED EVENT: Did not find a way to handle event :event/resume in the current active state: :state/loading See
UPDATE: it seems to only happen if I have a https://prismjs.com/docs/Prism.html#.highlightAll in :componentDidMount
...
I notice that :componentDidMount
gets called with old (previous) props while :componentDidUpdate
recieves the new props. Is this normal or perhaps indicative of some error?@U0CKQ19AQ I've been reading them but I guess I'm misunderstanding the intersection with RAD reports? I guess you're referring to the part about :componentDidMount
only getting called on initial render? I fail to see how it can lead to the data in the UI not being updated and why omitting that library call makes it all work.
I’m saying that componentDidMount and componentDidUpdate are REACT things. What you are seeing them do is controlled by React.
You should NOT be using them with reports. You should augment/edit the state machine of the RAD report/form if you want to augment the logic.
https://book.fulcrologic.com/RAD.html#_augmenting_form_behavior and the procedure for messing with reports is nearly identical, though the machine is different. Use the source of the machines
Hmm, they shouldn't be used with reports? I didn't know that. But I did try using ro/load-report
to just call the side-effecting function before returning the unmodified uism-env and it didn't seem to do the trick.
This level of customization is really at the UISM level, and has nothing to do with RAD per se. Other than you’re modifying a state machine that your report is using.
However, I've been trying to use :componentDidMount
on the defsc
ro/BodyItem
, not on the defsc-report
. It shouldn't be used there either?
React lifecycle hooks should generally be avoided everywhere because it complects React’s rendering with your own side-effects, and coupling the two is a bad idea. This is why RAD uses UISM to control the logic
but I think you’re getting confused by what React gives you in those, and may be running into react keys issues as well (perhaps it isn’t remounting the rows because it thinks they are the same component with just changed data)
I mean it's just a single function call that's supposed to decorate a dom element with some syntax highlighting. I did read your advice to Gene in this thread https://clojurians.slack.com/archives/C68M60S4F/p1660066678343479?thread_ts=1660065105.976959&cid=C68M60S4F and since my customization (single fn call) is so simple, I thought it was the right choice.
I did try it like this:
ro/report-loaded (fn [uism-env]
(.highlightAll js/Prism)
uism-env)
instead of using the lifecycle methods.I don’t see why the report-loaded would not work, other than if there was pagination
but it seems to me the right thing to do would be to create a react component that renders text with highlighting, and use that to render the value, instead of trying to be side-effect-y on a DOM React controls
Well, I mean I don't want to re-invent the wheel to accomplish syntax highlighting when there are mature libraries that do it. Perhaps you mean something else? Is there another means of applying such a post-rendering library or..?
I’m saying you should be carefully reviewing React docs for how to do that correctly, and you should isolate that need into a React component that is properly written:
(defsc HighlightedText [this {:keys [text]}]
{}
...proper code that is react compatible...)
Okay, I understand the direction you're suggesting. I thought I was making such a defsc component through this BodyItem but what you're saying about avoiding the lifecycle methods makes sense.
No, BodyItem is generating a React thing. Using a non-react library to modify the DOM it generated will never work right
Okay, thanks very much. Sorry if I missed this guidance in the docs 🙏 Back to the editor.
no worries. If you want to use low-level js libs with react, you have to be a ninja with low-level react and figure out all the gears
So always, always, always look for react components that are made using low-level libs, rather than trying to apply the libs directly.
Fulcro has nothing to do with your problem/task. You’re doing low-level DOM stuff. React is always in control of that. Fulcro is a data management library that allows you to render that state with React. the rendering is ALL react.
Just because you are typing cljs code while using Fulcro does not mean Fulcro has much to do with it 🙂
I actually never really learned React directly, most of my exposure is through Fulcro. I should probably commit a few weeks study time to level up.
Yeah, it’s nice to be able to ignore it when possible, and for simple UI stuff you can. But when you get to these kinds of low-level DOM things, it’s going to be ALL react and no Fulcro (other than knowing how to get your react stuff into cljs and Fulcro’s syntax correctly)
In the durable-mutation doc, there's mention of MutationStore but I can't find any protocol by that name https://cljdoc.org/d/com.fulcrologic/fulcro/3.4.4/api/com.fulcrologic.fulcro.offline.durable-mutations
the protocol is just general storage of EDN things in arbitrary place. Mutations just happen to be encoded as EDN
Are SettingsRouter
and Settings
(referred to in the RootRouter
) supposed to be the same thing?
https://book.fulcrologic.com/#HooksUseComponent:~:text=(defrouter%20RootRouter%20%5Bthis%20props%5D%0A%20%20%7B%3Arouter%2Dtargets%20%5BSettings%20User%5D%7D)%0A(def%20ui%2Droot%2Drouter%20(comp/factory%20RootRouter))%0A%0A(defrouter%20SettingsRouter%20%5Bthis%20props%5D%0A%20%20%7B%3Arouter%2Dtargets%20%5BPane1%20Pane2%5D%7D)%0A(def%20ui%2Dsettings%2Drouter%20(comp/factory%20SettingsRouter))
No. Scroll little up to the image. The code is incomplete. There should be a Settings comp contain the S. Router. I think the complete code is elsewhere in the book.