bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 209 forks source link

Detection of changes in files should be debounced #569

Closed vemv closed 6 years ago

vemv commented 7 years ago

Hi!

I think I've detected the following behavior:

The consequence is that I see A loaded first, then B, then C, instead of a consistent, atomic loading of A B and C into the new compiled js.

For most cases, this doesn't matter a lot (I think), because Figwheel will just reload the app 3 times very briefly and the user won't notice a thing.

But, this 'non-debounced' approach is suboptimal per se, and also affects me directly because I have the following setup:

;; project.clj:

:figwheel {:on-jsload "foo.bar.hard-reload" ...

;; foo.bar.cljs:

(defn hard-reload []
  (.reload js/location true))

With hard reloading in play, I start getting inconsistency errors that won't be automatically recovered (I have to manually reload again).

I hope the described issue is accurate!

Cheers - Victor

bhauman commented 7 years ago

We are currently waiting 50ms and gathering all the changes that happen in that period of time.

https://github.com/bhauman/lein-figwheel/blob/master/sidecar/src/figwheel_sidecar/watching.clj#L27

Waiting longer than 100ms affects the final response time of figwheel. So that points to this being configurable option.

I'm willing to take a PR for a configuration option to set the time we wait to collect changes. But I think the assumption that the time between file changes is only a few ms may be wrong.