I’m pretty new to clojure, and I’m trying to track down a bug in an existing re-frame application. Basically, if you navigate from the homepage to a subpage via a particular intermediate path (homepage > click on one link on the homepage > click on the subpage from the menu bar), one of the components on the subpage doesn’t update after a subscription updates. If you navigate to that subpage pretty much any other way, though, it works as expected and the component updates after the subscription updates. What are some things I should be looking for that might explain why this bug is happening?
The first step should be to read this and check if that's the case or not: https://cljdoc.org/d/reagent/reagent/1.0.0/doc/frequently-asked-questions/why-isn-t-my-component-re-rendering-
If it's not, the second step would to be compare your app's state after navigating to the subpage via the "bad" way with the app's state after navigating via any "good" way.
Looking at the state after navigating to the subpage both ways, the thing it’s subscribed to is there both times.
The component looks like
(defn foo-select
[]
(let [filtered-foo-ids (rf/subscribe [::subs/foo-ids])
foos (rf/subscribe [::subs/foos])]
(fn []
[:> Select
(util/data-test
{:disabled (empty? @foos)
:mode :multiple
...}
"foo-assignees")
...])))
Looking at that link, you wouldn’t expect this to rerender just because the ::subs/foo subscription was updated, because it’s not a ratom?Subscriptions return a Reagent reaction that behaves exactly like a ratom in terms of change propagation and view re-rendering.
In this particular case, is it foos
or filtered-foo-ids
that causes the issue?
foos
. In particular, when the bug is triggered, the select is always disabled
However, looking at the app-db in 10x, it looks like foos is a 2 element list
And what does util/data-test
do?
Looks like it assocs
a :data-test
item into the map when the environment isn’t prod
Just to be sure, add (js/console.log "FOOS" (empty? @foos))
right before [:> Select
and see if it prints false
when the corresponding input stays disabled.
If that's the case, I would start digging into the implementation of Select
.