omcljs / om

ClojureScript interface to Facebook's React
6.65k stars 364 forks source link

In reloadable workflow, "No queries exist for component path..." #896

Open decoursin opened 6 years ago

decoursin commented 6 years ago

When using a reloadable workflow (based on this and this), I'm getting the error:

No queries exist for component path (dashboard.core/Root dashboard.calendar/Calendar)

It seems to be caused only during the reloading phase of components of which I've modified and saved and "reloaded".

After digging a little deeper, it seems the components listed in the error message above are JS functions; so when modifying them, they change slightly, so when they're compared to the earlier-but-slightly-different-version of themselves they're no longer equal, which is what is causing the problem.

Here is some proof/examples of why this is true:

You can see the class path for (dashboard.core/Root dashboard.calendar/Calendar) is there:

=> (keys (get-in @(om/get-indexer reconciler)
                             [:class-path->query]))
([dashboard.core/Root dashboard.modal/Modal]
 [dashboard.core/Root dashboard.sidebar/Sidebar]
 [dashboard.core/Root dashboard.calendar/Calendar]
 [dashboard.core/Root])

However, when I get it, it returns nil:

=> (get-in @(om/get-indexer reconciler)
                        [:class-path->query (#'om/class-path (om/class->any reconciler Root))])
(not nil, but output elided.)

=> (get-in @(om/get-indexer reconciler)
                        [:class-path->query (#'om/class-path (om/class->any reconciler calendar/Calendar))])
nil

but it really isn't nil, I can see that by printing what's in there. You can see it by when I compare based on the name of the functions instead of the functions themselves, it works:

=> (defn to-names [coll] (map #(.-name %) coll))
=> (println (to-names (#'om/class-path (om/class->any reconciler calendar/Calendar))))
(dashboard$core$Root dashboard$calendar$Calendar)

=> (map (comp to-names first) (:class-path->query @(om/get-indexer reconciler)))
(("dashboard$core$Root" "dashboard$modal$Modal")
 ("dashboard$core$Root" "dashboard$sidebar$Sidebar")
 ("dashboard$core$Root" "dashboard$calendar$Calendar")
 ("dashboard$core$Root"))

=> (keys (into {} (map (fn [[k v]] [(map (fn [class] (.-name class))
                                                     k)
                                                v])
                                    (:class-path->query @(om/get-indexer reconciler)))))
(("dashboard$core$Root" "dashboard$modal$Modal")
 ("dashboard$core$Root")
 ("dashboard$core$Root" "dashboard$calendar$Calendar")
 ("dashboard$core$Root" "dashboard$sidebar$Sidebar"))

=> (get (into {} (map (fn [[k v]] [(map (fn [class] (.-name class))
                                                           k)
                                                      v])
                                         (:class-path->query @(om/get-indexer reconciler))))
                           (to-names (#'om/class-path (om/class->any reconciler calendar/Calendar))))
(output elided but you can trust me, the stuff's there.)