thheller / shadow-cljs

ClojureScript compilation made easy
https://github.com/thheller/shadow-cljs
Eclipse Public License 1.0
2.23k stars 173 forks source link

Reload the page on stale output? #1136

Closed vemv closed 2 weeks ago

vemv commented 11 months ago

Although it's fairly easy to make sense of the following message:

image

...it seems a little too high-friction of an scenario:

Because the fix is always the same, it seems reasonable to me to try automating it.

What would you think of an opt-in option that issued a location.reload() whenever output was stale?

...Perhaps there's some edge case under which the page would reload indefinitely. Which however could be quite trivially prevented by waiting 1.5s prior to to a refresh. That way, the browser is never possibly left busy-spinning.

Thanks - V

thheller commented 11 months ago

I'm more interested in hearing what you are doing, that leads you to this message in the first place? I don't see that message often and in all cases and automated reload loop would not fix it? Do you see this often?

Adding a reload is trivial, but I'd first want to figure out why you are seeing this in the first place and if there are maybe better solutions?

vemv commented 11 months ago

Thanks for the response!

I appreciate the caution.

I see this message when I:

thheller commented 11 months ago

Why ctrl+c in the first place?

vemv commented 11 months ago

It is my habit to Ctrl-C any processes whenever I start my work day (or other similar conditions e.g. I restart work after a good pause or after switching 'contexts', e.g. branches).

It's a simple way of ensuring that I'm not accumulating state that might produce odd issues somewhere in the stack.

It might sound like a strage habit to some, however my life has only been happier since adopting it.

Either way, Ctrl-C is a relatively common operation, for example think of adding dependencies.

jacobemcken commented 11 months ago

I have a build setup specifically for Storybook:

{:source-paths ["src/frontend" "src/storybook"]
  ...
  :storybook
  {:target :npm-module
   :as-regexp "-stories$"
   :output-dir "resources/public/js/storybook"}}}

When I create new files in src/storybook matching the regex stories$ they aren't picked up until I restart Shadow-cljs. But that might be another defect?

The most common reason to restart Shadow-cljs for me is that I don't understand much of what is actually happening under the hood. Is something cached, did I do something wrong without even knowing? So when I deal with a problem I don't understand, one of the attempts to solve it is restarting the other thing that I don't understand - just to make sure that I ain't caught for hours with a problem that could be solved following the wisdom:

Did you try to turn it off and on again?

I agree that restarting should be avoided at all costs.

Though, every time I see "Stale output"... reloading the browser has always worked. This makes me think: If the application knows it needs a reload... why does it need me to do it? Again I don't understand a lot of this... but that is the question that pops into my head.