fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
stuartrexking 2021-03-24T02:10:53.121600Z

I’m getting an error when composing routers. I’m following this structure here https://book.fulcrologic.com/#_routers

ERROR [com.fulcrologic.fulcro.routing.dynamic-routing:684] -  You are routing to a router  :router/SettingsRouter whose state was not composed into the app from root. Please check your :initial-state.

Jakub Holý 2021-03-24T11:15:21.124800Z

Also make sure to use the latest Fulcro

stuartrexking 2021-03-24T02:11:29.122300Z

What am I doing wrong?

stuartrexking 2021-03-24T02:16:37.122700Z

How do I compose from root when dealing with nested routers?

stuartrexking 2021-03-24T02:24:00.124100Z

I need to call dr/initialize! on mount.

stuartrexking 2021-03-24T12:04:52.125600Z

Clojure 3.4.20 I’m getting an error with dynamic router target

ERROR [com.fulcrologic.fulcro.components:874] -  Props passed to my.fancy.component/ComponentRoot are of the type PersistentVector instead of a map. Perhaps you meant to `map` the component over the props?

Jakub Holý 2021-03-25T11:34:59.149900Z

If the initial-state was wrong then the client DB content was wrong, which

(let [state (app/current-state APP)]
    (com.fulcrologic.fulcro.algorithms.denormalize/db->tree
      (comp/get-query Root) ; or any component
      ;; Starting entity, state itself for Root
      ;; otherwise st. like (get-in state-map [:thing/id 1]):
      state
      state))
would have shown you, now? Also fulcro-troubleshooting might have warned you about missing data in the client DB?

tony.kay 2021-03-25T15:41:58.150100Z

It’s easier to analyze that with Inspect DB Explorer, since that lets you click down the exact path from root you’re looking at

stuartrexking 2021-03-24T12:04:57.125800Z

my.fancy.component/ComponentRoot is a target

stuartrexking 2021-03-24T12:05:02.126Z

Any ideas?

Jakub Holý 2021-03-24T12:06:28.126100Z

What it says :-) Props must be a map. Why are you passing in a vector? Hard to help without seeing the code.

stuartrexking 2021-03-24T13:16:08.126300Z

I’m not pass props to the target? The docs state “The initial state parameters passed to such a router are forwarded to the first listed router target (if it has initial state).” This is the code

(defsc Target [this props]
  {:query         [:ui/value]
   :ident         (fn [] [:component/id ::target])
   :initial-state {}
   :route-segment ["target"]}
  (div {} "Target"))

(defsc Target2 [this props]
  {:query         [:ui/value]
   :ident         (fn [] [:component/id ::target2])
   :initial-state {}
   :route-segment ["target2"]}
  (div {} "Target2"))

(defrouter Router [this {:keys [route-factory route-props]}]
  {:always-render-body? true
   :router-targets      [Target Target2]}
  (when route-factory
    (route-factory route-props)))

(def ui-router (comp/factory Router))

(defsc RootComponent [this {:ui/keys [router]}]
  {:query         (fn [] [{:ui/router (comp/get-query Router)}
                          (uism/asm-ident ::Router)])
   :initial-state (fn [_] {:ui/router {}})}
  (div {}
    (ul
       (li
        (button {:onClick #(dr/change-route! this ["target"])} "Target"))
      (li
        (button {:onClick #(dr/change-route! this ["target2"])} "Target2"))
      (li
        (div {} "In")
        (ui-router router)))))

stuartrexking 2021-03-24T13:20:21.126500Z

3.4.20

stuartrexking 2021-03-24T13:20:26.126700Z

Doesn’t do it in 3.4.16

stuartrexking 2021-03-24T13:21:34.126900Z

Trying 3.4.19…

stuartrexking 2021-03-24T13:24:12.127100Z

Occurs in 3.4.19

stuartrexking 2021-03-24T13:28:21.127300Z

Something changed between 17 and 18.

stuartrexking 2021-03-24T13:29:24.127500Z

@holyjak Looks like you added logging for this in 17. https://github.com/fulcrologic/fulcro/commit/0bf8e61335be6fb50bc3c095de20e4e980863019

stuartrexking 2021-03-24T13:29:46.127700Z

So what am I doing wrong in the above?

stuartrexking 2021-03-24T13:40:55.128Z

@holyjak Would really appreciate if you give the code example above a quick look. It looks perfectly fine to me, so I’m not sure why I’m getting that error.

Jakub Holý 2021-03-24T14:20:37.128200Z

> I’m not pass props to the target Of course you pass props to the target router The problem is that you are passing it a vector instead of map. So look at the data you have. Why is it a vector? What is in it?

Jakub Holý 2021-03-24T14:20:55.128400Z

Also, have you tried fulcro-troubleshooting?

Jakub Holý 2021-03-24T14:22:46.128600Z

Can you replicate the warning with the code you posted above?!

stuartrexking 2021-03-24T16:20:22.129200Z

Yes. I get that error with that code.

Jakub Holý 2021-03-24T16:32:35.129400Z

your error says "ComponentRoot" but that is not in your code?! If it is the root component having issues, how did you register it with Fulcro?!

stuartrexking 2021-03-24T16:34:18.132100Z

I renamed the components to simplify the original code but I still get that error. Do you get an error if you run that code? It’s basically the same code as from the book.

stuartrexking 2021-03-24T16:34:51.133300Z

I can’t simplify that code anymore as an example router.

hadils 2021-03-24T16:34:59.133700Z

Hi. I am using form-save* without using defsc-form. What is the proper format for to-one and to-many data elements? Is each element an ident?

Jakub Holý 2021-03-24T17:35:27.134800Z

According to the error, the root component is the problem, not the router. Can you use the instructions here https://blog.jakubholy.net/2020/troubleshooting-fulcro/ for db->tree to see what the root props are? You can also js/console.log the root props

Jakub Holý 2021-03-24T17:36:02.135100Z

Your code snippet is missing your fulcro-app and it's initialization

hadils 2021-03-24T17:37:03.136100Z

The answer is yes. Now, how do I insert a new datom in Datomic? I am getting the following error:

:db.error/not-an-entity Unable to resolve entity: [:job/id #uuid "35994e32-533e-4fa1-9acd-292773a6bf70"] in datom [[:job/id #uuid "35994e32-533e-4fa1-9acd-292773a6bf70"] :job/location [:address/id #uuid "ffffffff-ffff-ffff-ffff-000000000300"]]
    cognitect.anomalies/category: :cognitect.anomalies/incorrect
     cognitect.anomalies/message: "Unable to resolve entity: [:job/id #uuid \"35994e32-533e-4fa1-9acd-292773a6bf70\"] in datom [[:job/id #uuid \"35994e32-533e-4fa1-9acd-292773a6bf70\"] :job/location [:address/id #uuid \"ffffffff-ffff-ffff-ffff-000000000300\"]]"
                           datom: [[:job/id #uuid "35994e32-533e-4fa1-9acd-292773a6bf70"]
                                   :job/location
                                   [:address/id #uuid "ffffffff-ffff-ffff-ffff-000000000300"]]
                        db/error: :db.error/not-an-entity
                          entity: [:job/id #uuid "35994e32-533e-4fa1-9acd-292773a6bf70"]
I think the error is caused by the fact that ]:job/id #uuid"..."] does not exist in the database yet.

Jakub Holý 2021-03-24T17:47:59.136400Z

I pasted it into the example.ui ns of fulcro-rad-demo, renamed root component to Root, and fixed imports. Seems to work, do not see this warning you have.

Jakub Holý 2021-03-24T18:26:49.136600Z

Are you inserting an entity and a dependent entity in one transaction and D doesn't understand you have both? I guess I can only refer you to Datomic docs. Or look what the RAD datomic save middleware does..

hadils 2021-03-24T18:38:20.136800Z

I am creating a new entity and then inserting dependent entities. I guess I need two calls to form-save* , one for the key and one for the remaining fieilds...

hadils 2021-03-24T20:34:16.137100Z

Resolved. Replaced a UUID with a TempID.

🎉 1
2021-03-24T20:36:47.138900Z

I’m calling transact! inside of a initLocalState declaration that doesn’t seem to be firing the mutation or erroring in any obvious way. I assume there’s a subtle binding issue with the this inside of initLocalState? any ideas what I might be doing wrong?

2021-04-09T18:43:18.455700Z

just realized I never responded to this. thanks @aleksander990 for the help trying to diagnose and @tony.kay for the detailed, super informative response – really can’t thank you enough for the time you’ve put into building and maintaining fulcro

🙌 1
stuartrexking 2021-03-24T22:58:45.139Z

I have the initialization code outside of the snippit. I think the issue is that I’m using a union query in a function query in my RootComponent. Function queries don’t support unions.

Aleksander Rendtslev 2021-03-24T23:21:26.139200Z

how are you passing this? initLocalState takes a function where the first parameter is this. If you try to pass it the this from the component definition it won’t work (I tripped over that)

2021-03-24T23:35:09.139400Z

I mean this is rebound inside of initLocalState, no? so it would be referring to that this

Aleksander Rendtslev 2021-03-24T23:58:47.141Z

I think it's more a matter of that function not having access to the outer "component or app thing". So you need to use the reference passed as the parameter to the function (eg this)