Code reloading happening multiple times

I’m wondering if anyone has run into this before as this has now happened twice.

Whenever I save a file, the project recompiles twice, sometimes three times. This is particularly frustrating with live reload on as it fires each time causing multiple page “reloads” (ie, topbar fires multiple times).

Has anyone run into this before? In the past, updating Phoenix seemed to fix it, but I’m on latest and going through some bisect hell trying to figure out what caused this so thought I’d ask here if it’s a common problem.

I haven’t seen it.

Did You try?

mix xref graph

This has happened to me when I accidentally load the live-reload javascript in the HTML multiple times. I’d open your browser and check and see if you’ve got multiple reload websockets open, that’s a sure sign that it’s running multiple instances in your browser.

1 Like

I’ve been using that a bunch this past week on another project to diagnose slow compilation times (to great success!) but did not think to use it here because it’s not recompiling multiple files, it just seems to be compiling multiple times. I just tried mix xref graph --sink lib/my_app/some_file.ex --label compile on some files anyway and I’m clean!

This sounds so familiar! I feel like last time this happened I may have had two copies of the app open, but that wasn’t the case this time. I finally tried the ol’ turn-it-on-and-off-again which of course now has me dealing with some postgres problem because this is an older computer I haven’t restarted in a while, ha, oh boy.

So postgres is fixed, I definitely don’t have multiple websocket connections and it’s still happening. I’ll have to dig into bisectting more, I’ve just made a lot db changes along the way so it’s annoying and I really just want to get back to actual work. I just asked here in case someone could be like, “It’s this!”

Thanks for the replies, everyone!

EDITED to add:

I found the post where someone gave an answer that solved this for me before. The solution was to upgrade esbuild. Esbuild has moved well past that version. Upgrading to latest doesn’t solve it and I can’t try downgrading to the version specified in that post as it’s no longer available.

OK, scratch that… this post did solve my problem, I just didn’t do it properly. I only upgraded the esbuild package but didn’t touch the version number in config/config.exs.

However, I don’t understand this. If I put 0.4.0 in config/config.exs, I get a warning: expecting esbuild version 0.4.0 but got . (ie, blank version). If I change the config/config.exs value to 0.13.5 (mix version is still 0.4.0) then everything works just fine. I’m pretty confounded by this…

EDITED to add: wait no, that makes sense. The hex package version and esbuild versions are not tied… adoi!