re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
Elliot Stern 2021-03-09T12:13:25.150Z

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?

p-himik 2021-03-09T12:17:49.150100Z

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-

👍 1
p-himik 2021-03-09T12:18:48.150400Z

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.

Elliot Stern 2021-03-09T12:20:32.150600Z

Looking at the state after navigating to the subpage both ways, the thing it’s subscribed to is there both times.

Elliot Stern 2021-03-09T13:31:46.150900Z

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?

p-himik 2021-03-09T14:14:34.151100Z

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?

Elliot Stern 2021-03-09T14:16:11.151300Z

foos . In particular, when the bug is triggered, the select is always disabled

Elliot Stern 2021-03-09T14:19:06.151500Z

However, looking at the app-db in 10x, it looks like foos is a 2 element list

p-himik 2021-03-09T14:25:16.151700Z

And what does util/data-test do?

Elliot Stern 2021-03-09T14:31:18.152100Z

Looks like it assocs a :data-test item into the map when the environment isn’t prod

p-himik 2021-03-09T14:35:40.152300Z

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.