# Anyone experienced multiple hot reload refreshes?

**URL:** https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312
**Category:** Troubleshooting
**Tags:** helix, shadow-cljs
**Created:** [September 11, 2023, 10:59pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312 "2023-09-11T22:59:32Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![rmschindler](https://clojureverse.org/user_avatar/clojureverse.org/rmschindler/32/3638_2.png) [@rmschindler](https://clojureverse.org/u/rmschindler)
#### Post date: [September 11, 2023, 10:59pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/1 "2023-09-11T22:59:32Z")

</div>

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_.

---

<div class="post-metadata">

### Author: ![p-himik](https://clojureverse.org/user_avatar/clojureverse.org/p-himik/32/4137_2.png) [@p-himik](https://clojureverse.org/u/p-himik)
#### Post date: [September 12, 2023, 6:28am UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/2 "2023-09-12T06:28:17Z")

</div>

Can you create a minimal reproducible example?

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [September 12, 2023, 6:56am UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/3 "2023-09-12T06:56:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rmschindler](https://clojureverse.org/user_avatar/clojureverse.org/rmschindler/32/3638_2.png) [@rmschindler](https://clojureverse.org/u/rmschindler)
#### Post date: [September 12, 2023, 2:48pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/4 "2023-09-12T14:48:04Z")

</div>

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.

 ![Screenshot 2023-09-12 at 7.38.08 AM](https://clojureverse.org/uploads/default/original/2X/5/59bdfde8268c536c8f854308a402dcd87d5a98c9.png)

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

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [September 12, 2023, 5:07pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/5 "2023-09-12T17:07:46Z")

</div>

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

```auto
[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)

---

<div class="post-metadata">

### Author: ![rmschindler](https://clojureverse.org/user_avatar/clojureverse.org/rmschindler/32/3638_2.png) [@rmschindler](https://clojureverse.org/u/rmschindler)
#### Post date: [September 14, 2023, 4:49am UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/6 "2023-09-14T04:49:13Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![rmschindler](https://clojureverse.org/user_avatar/clojureverse.org/rmschindler/32/3638_2.png) [@rmschindler](https://clojureverse.org/u/rmschindler)
#### Post date: [September 14, 2023, 3:49pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/7 "2023-09-14T15:49:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [September 14, 2023, 4:10pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/8 "2023-09-14T16:10:35Z")

</div>

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”?

---

<div class="post-metadata">

### Author: ![rmschindler](https://clojureverse.org/user_avatar/clojureverse.org/rmschindler/32/3638_2.png) [@rmschindler](https://clojureverse.org/u/rmschindler)
#### Post date: [September 14, 2023, 10:13pm UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/9 "2023-09-14T22:13:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [March 15, 2024, 10:13am UTC](https://clojureverse.org/t/anyone-experienced-multiple-hot-reload-refreshes/10312/10 "2024-03-15T10:13:56Z")

</div>

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