mount

jrychter 2016-04-26T14:16:48.000138Z

So — after 3 months of using mount with ClojureScript and Clojure, I am now certain that there is a bug somewhere in the interaction between figwheel and mount. My start functions are being called twice. Unfortunately, this is not something I can make into a nicely reproducible minimal test case — it happens in a large application.

tolitius 2016-04-26T15:01:39.000139Z

@jrychter: hmm.. I don't know figwheel well (I use https://github.com/adzerk-oss/boot-reload mostly). but sure, there can be a bug in the way cljs states are handled. I wonder if figwheel sometimes decides to reload all (not just incremental changes), which would reload mount itself

jrychter 2016-04-26T15:03:26.000141Z

Yeah, well, I can live with it for the most part. I just hit Command-R more often than usual. Sometimes the app breaks completely, because double-loading of my dispatcher namespace breaks event handling. I wrote a bit of code to detect this and at least log an error message so that I know what's going on (a one-shot atom reset to true in the start function is used to detect double-loading). Some amount of make clean and restarting cider+figwheel eventually gets me back to a workable state.

jrychter 2016-04-26T15:03:54.000142Z

But I just wanted you to know that there is a problem, because if I'm seeing it, then other people might see it too.

tolitius 2016-04-26T15:05:29.000143Z

definitely, I appreciate that

tolitius 2016-04-26T15:05:47.000144Z

would be also good to know what the problem is caused by though :simple_smile:

tolitius 2016-04-26T15:07:17.000145Z

this was one of the many reasons I moved off of lein.. you can never be sure "what overwrote what", but of course there are a lot of great tools build around lein, and they are primarily used. so definitely need to get to the bottom of this..

tolitius 2016-04-26T15:08:03.000146Z

which state (that is restarted twice) in your use case is most painful to deal with, is that some kind of a web socket?

tolitius 2016-04-26T15:12:56.000147Z

just "double lading" should not break mount: i.e. states that are started would not be restarted unless their namespace is wiped. but even then they would be stopped first and then restarted

tolitius 2016-04-26T15:13:22.000148Z

I wonder if you could try ^{:on-reload :noop} and still see a problem

tolitius 2016-04-26T15:13:28.000149Z

https://github.com/tolitius/mount#on-reload

jrychter 2016-04-26T17:39:55.000151Z

Well, in this case I wouldn't blame lein itself, as ClojureScript is managed by figwheel in dev environment. The double loading is a problem because I use a dispatcher pattern, where a single dispatcher with a pub/sub calls event handlers. Every namespace registers a bunch of event handlers. Obviously it's a problem if handlers get registered twice, because they will be called twice. And it's a disaster if the dispatcher start function gets run twice, because that one creates the bus and pub. It basically means losing all subscriptions.

jrychter 2016-04-26T17:40:20.000152Z

Now I'm afraid of touching that dispatcher.cljs file. If I touch it, things might break…

jrychter 2016-04-26T17:41:02.000153Z

But I'll try the :on-reload :noop thing.

jrychter 2016-04-26T17:42:59.000155Z

The (2)s are next to every namespace that was just reloaded (all fifteen or so). Everything was done twice.

jrychter 2016-04-26T17:50:12.000156Z

The :on-reload :noop in dispatcher.cljs doesn't seem to change much. Well, except that after the change my app doesn't even start, because of double-loading. But I have no idea why after some changes it works and after others it doesn't. Even cleaning JavaScript inbetween doesn't help. Back to working version for now.

jrychter 2016-04-26T17:50:41.000157Z

But perhaps there is some tracing/logging that I could enable to learn more about where the problem is?

tolitius 2016-04-26T19:56:00.000158Z

> the (2)s are next to every namespace that was just reloaded the only way this would happen (initial thinking) if there is more than a single mount running: i.e. two mounts are looking after their states..

tolitius 2016-04-26T19:57:54.000159Z

i.e. almost like "two mounts" are brought in (perhaps as deps) and started

tolitius 2016-04-26T20:00:19.000161Z

do you ever see #'partsbox.core/state starting twice before any reloads?

tolitius 2016-04-26T20:08:26.000163Z

@jrychter: try mount-0.1.11-SNAPSHOT.jar it will log states it mounted / defined

tolitius 2016-04-26T20:09:02.000165Z

should allow for a better discovery on when the "second" mount comes into play