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.
Also make sure to use the latest Fulcro
What am I doing wrong?
How do I compose from root when dealing with nested routers?
I need to call dr/initialize! on mount.
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?
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?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
my.fancy.component/ComponentRoot is a target
Any ideas?
What it says :-) Props must be a map. Why are you passing in a vector? Hard to help without seeing the code.
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)))))
3.4.20
Doesn’t do it in 3.4.16
Trying 3.4.19…
Occurs in 3.4.19
Something changed between 17 and 18.
@holyjak Looks like you added logging for this in 17. https://github.com/fulcrologic/fulcro/commit/0bf8e61335be6fb50bc3c095de20e4e980863019
So what am I doing wrong in the above?
@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.
> 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?
Also, have you tried fulcro-troubleshooting?
Can you replicate the warning with the code you posted above?!
Yes. I get that error with that code.
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?!
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.
I can’t simplify that code anymore as an example router.
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?
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
Your code snippet is missing your fulcro-app and it's initialization
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.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.
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..
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...
Resolved. Replaced a UUID with a TempID.
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?
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
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.
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)
I mean this
is rebound inside of initLocalState, no? so it would be referring to that this
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)