clojurescript 2024-11-13

Hi, I have this function on a re-frame app (using reitit for routing)

;; core.cljs namespace
(defn router-component []
  (let [current-route @(re-frame/subscribe [::subs/current-route])]
    [:div
     [myapp.views/main] ;; <------- Issue here
     (when current-route
       [(-> current-route :data :view)])]))
with the main inside different namespace, in this case views it fails when reloading the page with:
Error: Assert failed: Invalid Hiccup form: [nil]
 (in myapp.core.router_component)
(valid-tag? tag)
If reloading from editor, when change the code (figwheel) it works. My app structure follow more or less what is at https://github.com/metosin/reitit/blob/master/examples/frontend-re-frame/src/cljs/frontend_re_frame/core.cljs Any advise here? Thanks!

The problem is actually, probably, with [(-> current-route :data :view)] since it might potentially return nil. Just do something like:

(when-let [view (-> current-route :data :view)]
  [view])

Not sure, because even if I totally remove that part, I still have the same error, I mean, keep just:

(defn router-component []
  (let [current-route @(re-frame/subscribe [::subs/current-route])]
    [:div
     [myapp.views/main] 
]))

So which component becomes nil then? There must be something dynamic going on, as myapp.views/main cannot be nil.

(Also, make sure that the code above is actually the one that's running and there are no weird caching issues.)

I just figure it out, is another function inside my views namespace where I call rfe/href .. and cause issues, but not totally related, so all good I think so

Thanks for the quick response,