omcljs / om

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

`set-query!` can cause Om to attempt to focus an old query with a new path #779

Closed Peeja closed 7 years ago

Peeja commented 7 years ago

Demonstrated here, on the devcard om.devcards.core/test-query-setting.

The card shows the current user's pets. Clicking a pet in the sidebar selects the pet, and shows more info in the main area. This is accomplished with set-query!.

However, when "Jasmine" is clicked, the app throws an error. The error comes from the indexer, which is trying to focus the old root query,

[{:om.devcards.core/route-data
  [{[:app/current-user _]
    [{:user/pets [:db/id :pet/name]}]}
   {[:pet/by-id 0]
    [:db/id :pet/name :pet/favorite-toy]}]}]

to the new path, [:om.devcards.core/route-data [:pet/by-id 1]]. That is, the query it's focusing has Alfred's ident, [:pet/by-id 0], but the path it's focusing has Jasmine's, [:pet/by-id 1]. This leads to an error in query-template.


It's also entirely possible I'm doing something wrong, in which case I'd be happy to be told what that is. 😃

Peeja commented 7 years ago

After further investigation: In set-query!, after this swap!, (get-query c) is correct, where c is the PetsPage component whose query is being set, because it finds the new query in the ::queries in the app state. However, (get-query root) has the wrong ident, as it has no entry in ::queries. This is why the subsequent p/reindex! fails.

anmonteiro commented 7 years ago

fixed 1ce79f114fc602660a1c2e2e09ac4e9d85f8b54f