shadow-cljs

Ryan 2025-09-29T18:54:25.978669Z

I have an event that triggers a js/setInterval to periodically dispatch a reload event every 10 seconds or so. In local, with shadow-cljs watch, it seems hot reload will cause duplicate intervals to be created.. any tips for dealing with hot-reload and intervals in local dev? sort of hammers servers after awhile

Ryan 2025-09-30T11:38:04.775679Z

Hmm that does seem like a good approach.. I just wish js had better visibility into intervals so I could see where it’s getting caught up.. the event that initiates the interval only appears to run once, but eventually over the course of an hour or so the 10 second interval slowly becomes like 40ms.

Ryan 2025-09-30T11:38:26.910089Z

in production, it holds pretty steady so I imagine is has to be with hot reloading

Ryan 2025-09-30T11:52:30.813489Z

Ooh, my re-frame fx util namespace initializes an atom to store a reference to the interval.. I’m going to try to define that atom in the init function as mentioned and reference it from the fx library class

Roman Liutikov 2025-09-29T18:57:38.419099Z

Use before load hook to clear the interval

🙏 1
thheller 2025-09-30T06:13:32.888209Z

https://code.thheller.com/blog/shadow-cljs/2019/08/25/hot-reload-in-clojurescript.html or install it in the init fn as described here. that is only called once. it is your code calling it, so you must have some safeguard to not call it again or clear it before as Roman said