Code reloading not working for all files?

I’m a little confused wrt. how the hot code reloading works in Phoenix. Even though I have code_reloader: true, set in my dev.exs, I often find myself having to forcibly restart my Phoenix server (ie. Ctrl-C twice, then re-run mix phx.server) when editing files like router.ex to see an effect of my changes.

Is that expected behaviour, or is this indication of some kind of bug?

What does happen if you do recompile() in iex -S mix phx.server? If it results in :noop then you might have other processes compiling your code at the same time as phoenix. The code_reloader basically compares modification timestamps on source files as as well as compiled files and if they don’t match then it compiles and loads the new compiled file. If something else compiles files sooner then the code_reloader can’t detect the change anymore.

1 Like

Ah, so I guess it could be because I’m using ElixirLS and Elixir Linter in VSCode, that are also compiling stuff. I guess I’ll try disabling them, see if that helps.

ElixirLS compiles into .elixir-ls for exactly that reason. I don’t know about other extensions though.

1 Like

@LostKobrakai yeah, ElixirLinter is unmaintained, and now I think of it, I didn’t have problems before I installed that. I’ll try without it for a while to see if it reoccurs. Thanks for the pointers.

The router.ex is one of those files that require an explicit restart of the server.

As a rule of thumb, when you change files that are not a controller, a context, schema or view, you need to restart.

Also you need to restart when you add or remove any files.

This is at least my observation…

The router should reload just fine. the endpoint doesn‘t though.

1 Like