Fork me on GitHub

We've been hitting this assert randomly in production code recently. All fine during dev but once compiled the advanced build to staging, it breaks.

(defn console
  [level & args]
  (assert (contains? @loggers level) (str "re-frame: log called with unknown level: " level))
  (apply (level @loggers) args))


Is there some specific level that triggers it?


We don't even use any loggers


That's fine. But does the assert message above include the level? And what's the stacktrace? I'm 80% certain that there's some library in your dependencies that changes @loggers but does it in an improper way.


we're on 0.11.0. upgrading to 1.2.0 breaks another thing. it's a bit of a crisis


Hmm. That is strange. And 0.11.0 doesn't have any obvious way to break loggers, unless the compiler ignores the ^:private metadata. I would try to print the result of (re-frame.loggers/get-loggers) right at the start of the application, just to double check. If that doesn't provide any insight, I would copy re_frame/loggers.cljc into my own code and add a watcher to the loggers atom there to see when exactly it is modified with (js-debugger) , plus an extra statement before that assert to log the current state of loggers.


Also, that particular logging message is this line:

(console :error "re-frame: no" (str kind) "handler registered for:" id)
So seems like there's also an issue in your app's code.


{:log #object[bound log], :warn #object[bound warn], :error #object[bound error], :debug #object[bound debug], :group #object[bound group], :groupEnd #object[bound groupEnd]}


Yeah, all fine here.


but that's when there is no bug as well in production


it happens randomly in some builds


So it's tied to a build, and not some specific behavior?


well, we thought we solved it by making something lazy non-lazy, this helped solving the bug last time


but now I built some new feature and it starts happening again. Only in release builds :((


and there's a demo soon... this is stressing me out.


Then do all the things I described and try again and again to trigger it on a release build in staging. I don't see any other way to get useful information from it.


now I'm getting this:


starting with a clean build solved that problem, still weird


I installed an override of re-frame loggers in our production build


(defn console
  [level & args]
  #?(:cljs (.log js/console "level" (str level)))
  #?(:cljs (.log js/console "has-logger" (some? (level @loggers))))
  ;; (assert (contains? @loggers level) (str "re-frame: log called with unknown level: " level))
  ;; (apply (level @loggers) args)


And what does @loggers contain at this point?


I'm going to take a look at that next, but this error might hint at what's really going wrong.;.


Not sure - unless the JS console is mixing things up, that error is after those logged statements. So it can't affect @loggers at that point. Unless it has happened before, up the log, as well.


I got curious and google that this.options.useExtendedSearch stuff and most hits seem to relate to a fuse.js fuzzy search library. any chance you're using it and something horrible happens during advanced compilation?


yep we use that. thanks, looking into this


We're deploying with optimizations simple now until we get this sorted


Thanks for the moral and technical support


That project is not open source, is it?


unfortunately not


with pseudo-names true our build succeeds

👍 3

we upgraded to the newest CLJS + all the libs that were breaking with google closure


and guess what... it compiles/works again with advanced


Sweet! My guess is that one of the libs didn't have that precious ^js or something like that in the right place.


Lately I've been working on a re-frame + react native project and noticing that some react libraries in the JS ecosystem now use hooks as their main/only API. So far I've avoided using hooks with re-frame because it seems they somewhat go against the model of doing things in events, and using view components only to render the state created by the events. Does anyone use hooks with re-frame? I wonder if it could become a problem in time that newer JS react libraries mainly use hooks and don't provide their functionality otherwise. For example, maybe I need to do X, and library Y does just what I need and is the most/only community supported library that does X. Then I realize library Y only exposes X through a hook. So do I just avoid library Y and write this functionality myself? Maybe I'm misunderstanding something, as I haven't used hooks much in the past, and I can't say I'm a well-seasoned re-frame user.


Hooks by themselves are OK, as long as you control the component's state yourself. And you should be able to wrap any such component into a hook-less one. What's not OK is when e.g. some component just asks you for a URL and then loads data from that URL. But such cases are rather rare, at least in my experience.


Hmm, so for example, if I want to use an auth library that has a hook like useAuthClient that gives me a function like login - I'd want to call login in a re-frame effect, but for reasons I'd want to call it on app initialization and only then. I guess my confusion comes with figuring out the proper way to get that login function in a re-frame event if I have to obtain if from within a component. On the one hand I have the app initialize event which doesn't have much to do with components, yet I want to call a function I can only get from within a component. I could be thinking about this all wrong, though.


Ah, that's an example of a bad hook. It hides the state, making it opaque for re-frame. And of course it's not really specific to hooks, although they facilitate it. I would try my best to avoid using such code altogether. But if the login function can be called outside a component, you can pass it to an event and make a custom effect that would call a function that you pass to it.


Ah I see. Thanks for the info and tips. So far, I've managed to avoid hooks with re-frame.