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-25T00:19:57.141200Z

It’s strange. The router-props are an ident [:component/id :ns/component] to the target. Should they be a map? @tony.kay do you have any idea on how I can debug this further?

stuartrexking 2021-03-25T00:20:33.141400Z

(defrouter AuthenticatedRouter [this {:keys [route-factory route-props]}]
  {:always-render-body? true
   :router-targets      [DashboardRoot CompanyRoot PersonRoot InvestorRoot]}
  (when route-factory
    (do
      (log/spy route-props)
      (route-factory route-props))))

(def ui-authenticated-router (comp/factory AuthenticatedRouter))
The route-props are an ident.

stuartrexking 2021-03-25T00:20:53.141600Z

And the error is

timbre_support.cljs:80 ERROR [com.fulcrologic.fulcro.components:874] -  Props passed to fierce.pyxis.dashboard.ui/DashboardRoot are of the type PersistentVector instead of a map. Perhaps you meant to `map` the component over the props?

tony.kay 2021-03-25T00:22:50.141800Z

have to see more of the composition in code

stuartrexking 2021-03-25T00:27:48.142Z

(defsc AuthenticatedRoot [this {::keys   [router]
                                :ui/keys [sidebar mobile-sidebar]}]
  {:query         [::auth-root
                   {:ui/sidebar (comp/get-query sidebar/Sidebar)}
                   {:ui/mobile-sidebar (comp/get-query sidebar/MobileSidebar)}
                   {::router (comp/get-query router/AuthenticatedRouter)}
                   (uism/asm-ident ::router/AuthenticatedRouter)]

   :ident         (fn [] [:component/id ::auth-root])

   :initial-state (fn [_] {:ui/sidebar        {:ui/sub-sidebars [(dashboard-sidebar-items)
                                                                 (discover-sidebar-items)
                                                                 (account-sidebar-items)]
                                               :ui/account      (comp/get-initial-state account-ui/AccountRoot)}
                           :ui/mobile-sidebar {:ui/items                   mobile-main-sidebar
                                               ::account/name              "Kathrin Mutinelli"
                                               ::account/profile-image-url "/images/kathrin-mutinelli.jpg"
                                               ::organisation/name         "Stratico"
                                               :ui/dropdown-open?          false
                                               :ui/open?                   false}
                           ::router           {}})}
  (log/info router)
  (let [active-route (some-> (dr/current-route this this) first keyword)]
    (div {:className "h-screen flex overflow-hidden bg-white"}
      (sidebar/mobile-sidebar (assoc mobile-sidebar :ui/active-route active-route))
      (sidebar/sidebar (assoc sidebar :ui/active-route active-route))
      (router/ui-authenticated-router router))))

(def ui-authenticated-root (comp/factory AuthenticatedRoot))

stuartrexking 2021-03-25T00:28:23.142200Z

That logs the router correctly, but when it passes the props through the router as route-props, it’s an ident.

tony.kay 2021-03-25T00:45:26.142400Z

so it is not working at all in latest, but works .4 back?

tony.kay 2021-03-25T00:45:40.142600Z

not just that it says an error, but that it is actually busted?

tony.kay 2021-03-25T00:45:56.142800Z

in that case, a minimal repro case and an issue would be ideal

stuartrexking 2021-03-25T00:45:56.143Z

I don’t think it’s working at all. The logging was added 17

stuartrexking 2021-03-25T00:46:35.143200Z

Would I expect an error if it was working? Why would a route target receive an ident rather than props. That doesn’t sound correct.

stuartrexking 2021-03-25T00:47:46.143400Z

Routing works, but I get that error on every route change.

stuartrexking 2021-03-25T01:10:26.143600Z

@tony.kay Here it is https://gist.github.com/stuartrexking/89e92a917c36ad75cabc1b80be7d8bdc

stuartrexking 2021-03-25T01:11:03.143800Z

It’s the authenticated flow that’s the problem.

tony.kay 2021-03-25T01:15:02.144400Z

line 70

tony.kay 2021-03-25T01:15:09.144600Z

do not pass an extra param to get-query

tony.kay 2021-03-25T01:15:19.144800Z

that disables dynamic query, which the router needs

stuartrexking 2021-03-25T01:15:41.145Z

I’ve pulled those components from various namespaces and was trying different things. I don’t have it in my actual code. The gist now reflects that.

tony.kay 2021-03-25T01:15:45.145200Z

Also, that component should prob have an ident, though technically not required. I’m guessing your extra arg to get-query is the problem

stuartrexking 2021-03-25T01:16:18.145400Z

It’s not the problem.

stuartrexking 2021-03-25T01:16:32.145600Z

Well, I’ve removed it and I still get the error.

tony.kay 2021-03-25T01:17:17.145800Z

OH

tony.kay 2021-03-25T01:17:31.146Z

you’re using fn for initial state, but you’re using the magic notation…that won’t work

tony.kay 2021-03-25T01:17:36.146200Z

72

tony.kay 2021-03-25T01:17:42.146400Z

and 56

stuartrexking 2021-03-25T01:18:00.146600Z

Looking..

tony.kay 2021-03-25T01:18:17.146800Z

you have to call get-initial-state just like get-query if you’re using a fn form for initial state

tony.kay 2021-03-25T01:19:20.147200Z

and https://book.fulcrologic.com/#_initial_state_2

stuartrexking 2021-03-25T01:21:13.147400Z

Rage Emoji.

stuartrexking 2021-03-25T01:21:54.147600Z

Thanks Tony. Really appreciate it.

tony.kay 2021-03-25T01:39:58.147800Z

that fix it?

stuartrexking 2021-03-25T01:41:34.148Z

Just working through it but it looks like it.

tony.kay 2021-03-25T04:30:13.148400Z

initLocalState should not be used this way

tony.kay 2021-03-25T04:32:02.148600Z

you can use it in normal lifecycle methods…but initLocalState is sort of mixed into the low-level js constructor.

tony.kay 2021-03-25T04:33:58.148800Z

I/O, in general, should not, IMO, be tied to component lifecycle, either. Your data model and logic should drive the UI, not the other way around (the exception being a user-event which is obviously given to you from the UI). When you couple your data lifecycle with your UI component lifecycle you’re asking for trouble (or at least a lot of I/O you don’t need).

tony.kay 2021-03-25T04:35:36.149Z

So, for example, a UI event triggers a route change. A route change calls will-enter (not a UI lifecycle, but a routing lifecycle…subtle but important difference). That, in turn, could trigger something on a UISM that is managing the overall mechanisms of your UI. This is basically how RAD does it: a form is just UI and event triggering on a UISM, where the overall life of the form is managed in logic/data.

tony.kay 2021-03-25T04:37:06.149200Z

Another way of saying it: tie your transactions and I/O to user driven things whenever possible. The user activated a route is different than some component on that route “appeared”.

tony.kay 2021-03-25T04:37:35.149400Z

they happen very closely in time, but are modeled in code very differently.

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

Aleksander Rendtslev 2021-03-25T17:28:38.152900Z

Am I using dr/change-route! wrong? Here’s what I’m doing:

;; Where I do it:
(dr/change-route! this (dr/path-to TagPage "my-id"))

;; My component
(defsc TagPage [this {:keys [node/id] :as rest}]
  {:ident :node/id
   :query [:node/id :node/name]
   :initial-state (fn [{:node/keys [id]}]
                    {:node/id id
                     :node/name ""})
   :route-segment ["page" :node-id]
   :will-enter (fn [_app {:keys [node-id]}]
                 (log/info "Here it is: " node-id)
                 (dr/route-immediate [:node/id node-id]))}
  ;; Render logic
)

;; The warning I'm getting:
[com.fulcrologic.fulcro.algorithms.indexing:103] - component .../TagPage's ident ([:node/id nil]) has a `nil` second element. This warning can be safely ignored if that is intended. Props were [:node/id "my-id"]
It seems like it’s giving the component the parameters [:node/id "my-id"] as opposed to {:node/id "my-id"} I can’t figure out why?