day8 / re-frame

A ClojureScript framework for building user interfaces, leveraging React
http://day8.github.io/re-frame/
MIT License
5.42k stars 715 forks source link

reg-global-interceptor is not code reloading friendly #655

Closed p-himik closed 3 years ago

p-himik commented 3 years ago

Calling reg-global-interceptor multiple times with the same exact interceptor (which is exactly what happens with code reloading) will add multiple copies of the same interceptor to the global interceptors queue.

Here's my current workaround:

(def reg-global-interceptor
  (if re-frame.interop/debug-enabled?
    (fn [interceptor]
      (let [existing-interceptors (re-frame.settings/get-global-interceptors)]
        (if (some #(= (:id %) (:id interceptor)) existing-interceptors)
          (do
            (rf/clear-global-interceptor)
            (doseq [i existing-interceptors]
              (rf/reg-global-interceptor
                (if (= (:id i) (:id interceptor))
                  interceptor
                  i))))
          (rf/reg-global-interceptor interceptor))))
    rf/reg-global-interceptor))
superstructor commented 3 years ago

Thanks for the bug report @p-himik

Fixed in v1.1.2