Anyone experienced multiple hot reload refreshes?

I’ve been suffering a certain phenomenon. I’m developing a React app (via Helix), and using shadow-cljs. When my app is tiny—all in one file—, and I make a change to the code, in the browser it refreshes once. When my app grows to more-than-one file, and I make a change to the code, the browser refreshes, and then a few seconds later (between 1 and 3, say), refreshes again.

I am hoping this is something someone else has experienced, and knows how to fix. One file, one refresh; multiple files, more-than-one refresh.

One more note: when the browser refreshes, it does it twice.

Can you create a minimal reproducible example?

Look at the browser console. You can toggle it to preserve the log between reloads. If shadow-cljs is doing things multiple times the log will tell you. shadow-cljs otherwise just calls you :dev/after-load hooks, what those do is out of its control. shadow-cljs itself does not know how to do a full page reload.

Could also be your editor delaying file saves so long that a hot-reload triggers before all files are saved. Or something touching the files after save. shadow-cljs just watches the files, so any changes made will trigger a reload.

My editor is NeoVim, BTW; I know it is not saving changes ‘later’, because the moment I make a change in the code, and save the file, the first refresh which occurs as a result of my change reflects those changes in the browser.

EDIT: I now have further confirmation that the files aren’t being updated ‘later’ somehow: I checked the timestamps (via % ls -lT) of the files after my code change, and then again after the two extra refreshes, and they were identical.

Let me recap the issue, for clarity: when I make a change to a file, I see a refresh in the browser. Then a few seconds later, two more refreshes occur.

Here’s what the console log shows.

  1. What I see after a manual refresh of the browser.
  2. What I see after a code change.
  3. What I see after the two extra refreshes.

To be clear, between (2) and (3), I am simply waiting a few seconds; and it happens on its own.

No clue. You can add :log {:level :debug} to the shadow-cljs.edn top level, so {:log {:level :debug} :builds {...} ...}, and restart shadow-cljs. That’ll do a tiny bit more logging.

I suspect you’ll see something like this getting logged

[2023-09-12 19:04:46.770 - FINE] :shadow.cljs.model/resource-update - {:namespaces #{demo.browser}, :deleted #{}, :updated #{demo.browser}, :added #{}, :macros #{}}

Otherwise try to eliminate all other running processes which might be touching the files in some way. If you don’t see the above log line re-appearing after you made the actual change I’m even more out of ideas. 100% of the time people have reported this it was related to other tools mucking with the files (i.e. linters, formatters, generators, etc)

Thanks, the {:log {:level :debug}} trick helped me find a clue to what’s going on, simply because of the timestamps it offered. I found that my source directory is somehow being touched after the first (expected) refresh, which triggers the other (unexpected) refreshes.

I wonder what could be touching the directory—by ‘touching’ I mean its timestamp is being modified. Hmm…

I found the culprit. It is one of the processes that comprise the Spotlight service on macOS, called mds. It indexes all the files on the computer to afford Spotlight searches, for instance. In its indexing it touches directories. (Trying. Hard. Not. To. Rant.) …So anyway, Spotlight can be configured (under the ‘Siri and Spotlight’ section of the System Settings app) to ignore particular folders, etc.

Making the change to how Spotlight is configured has mitigated the mysterious and annoying issue of multiple refreshes arising from a single code change.

That is very strange. Spotlight usually only reads the files and doesn’t modify them? I would expect this issue to come up frequently if it did? I certainly have not ignored anything in Spotlight and never had an issue on my mac? Do you maybe have some other app installed that uses Spotlight that does the actual “touching”?

I can only guess that it has something to do with iCloud functionality. I agree: it’s very, very weird for any file to be touched by an indexing service. Even on my mac, it was an intermittent thing. And it wasn’t the files it touched, but the directories. Very strange indeed. At any rate, I am satisfied that it works now, so this minor annoyance which was like death by a thousand cuts has been alleviated.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.