Fork me on GitHub
#fulcro
<
2024-01-27
>
Joe R. Smith01:01:48

Why isn't com.fulcrologic.fulcro.application/app-root set in the runtime atom when mounted?

Joe R. Smith01:01:27

What I'm trying to get at is the root-- React18 wants you to use createRoot to make the root and then call render on that on subsequent updates, so I need a handle on the root. I currently just put it in a separate atom, e.g., I override :render-root! with:

(fn [a, r]
  (let [root (or @*root (reset! *root (createRoot r)))]
    (.render root a)))

tony.kay03:01:21

I’m not aware it wasn’t. The app itself has an internal place where it stores app root. You can mount 400 apps on one page (like the Fulcro book, for example, which does just that), so a single top-level atom is not where you’d want it. (application/app-root an-app) is how you are intended to get it.

1
tony.kay03:01:29

Each app has a runtime-atom that is meant to hold all manner of things like this, including whatever else you’d like to put there (as nsed kws, of course).

Joe R. Smith15:01:28

That function returns nil for me when called on the app produced by com.fulcrologic.rad.application/fulcro-rad-app

tony.kay17:01:21

Web or native UI?

tony.kay17:01:44

I may have messed it up with react 18.

Joe R. Smith17:01:48

Anything compelling about 18? I’m happy to drop down to 17 if it isn’t important.

tony.kay17:01:51

Not for fulcro. Try it.

👍 1
tony.kay17:01:52

I've never needed the app root outside of initial render... Which is internal, so not surprised if it broke and no one noticed

Joe R. Smith17:01:46

Yeah- only reason I noticed was I wanted to stop the react warning about using the deprecated render function.

tony.kay17:01:16

What do you need app root for?

Joe R. Smith17:01:32

With react 18, you call createRoot and then call render on the result. If you already have a root, then you just call render. e.g., I override :render-root! with:

(fn [a, r]
  (let [root (or @*root (reset! *root (createRoot r)))]
    (.render root a)))
I want to ask the app for the root, instead.

tony.kay17:01:41

Why aren't you using my function?

tony.kay17:01:05

with-react-18

Joe R. Smith17:01:31

is there a react 18 specific render-root! function I missed?

Joe R. Smith17:01:10

where is it? I missed it

tony.kay17:01:11

In the react 18 ns. Not at a computer. Separate ns for bw compat

Joe R. Smith17:01:47

ah, got it. I’ll look for it, thanks (also not at a computer ;) )

Jakub Holý (HolyJak)21:01:24

Merge (com.fulcrologic.fulcro.react.version18/react18-options) into the app config. See e.g. https://github.com/holyjak/minimalist-fulcro-template-backendless/blob/main/src/com/example/app.cljs#L15-L29

👆 1
👍 1