pfun
Code reloading in `lib/<appname>` no longer works with 1.7.0-rc.0
Using 1.7.0-rc.0 for some experiments and it quickly became obvious that while code reloading is working as usual in lib/<appname>_web and elsewhere in the app, it is not working in lib/<appname>. This is a vanilla/out of the box application. I added phx.gen.auth to have some more code to edit that really should cause a reload.
I have tried this with a couple different versions of Elixir and Erlang. I tried going back to 1.6 and confirmed it’s working fine there. Finally, I used a different laptop (tested MacOS 12.4 and 12.6) and the same thing was observed.
Anyone else seen this? Third-party confirmation would be appreciated as well!
Marked As Solved
beepbeepbopbop
Can you clarify whether or not you are using LiveView based authentication system? When you run mix phx.gen.auth Accounts User users, you are given the prompt:
An authentication system can be created in two different ways:
- Using Phoenix.LiveView (default)
- Using Phoenix.Controller only
Do you want to create a LiveVIew based authentication system? [Yn]
I can only assume that you are using LiveView and if that’s the case, I think I know why your changes to your user.ex file aren’t being reflected. If you check endpoint.ex, you can see that plug Phoenix.CodeReloader is specified. So every request to your dev server goes through this plug and runs Phoenix.CodeReloader.reload(ExampleWeb.Endpoint) for you. If you were to make your logger change and reload the page, this ought to work and your change honoured.
Now, this doesn’t work with LiveView since they are process based. Once your LiveView connection is mounted (as in your LV has successfully mounted in both calls), all changes will be pushed to the LV, and won’t go through the Phoenix.CodeReloader. You would need to update something your web directory, or run recompile in your iex session.
I am not absolutely sure that this is the case, but give it a go without LV and see if you can replicate the issue you have.
Also Liked
pfun
Alright so as @beepbeepbopbop was suggesting, this is apparently just normal behaviour. I used Phoenix 1.6.15 to make a new app and did:
mix phx.gen.live Things Thing things title:string count:integer
Added routes as instructions say, started server, made a ‘Thing’. Then I added a validation in thing.ex, e.g. add:
|> validate_number(:count, less_than: 10)
Made a new Thing, and it let me make it with count: 500. Refresh the page and now the validation applies. Same with adding loggers. Nothing happens until you refresh the page (or recompile() when using iex). I definitely just want this to happen automatically, so I suppose I have to do the live_reload config ugliness I mentioned earlier.
I worked on an app early on with liveview (that unfortunately I can’t get to work at all anymore) and I really find it hard to believe I never noticed or encountered this. I did not make any changes to the live_reload config in that other app, totally vanilla as far as that’s concerned…
But, anyway, seems clear this is just expected and not a bug at all, folks. Thanks for all your input!
beepbeepbopbop
Is this really the intended behaviour?
Well, I would imagine so. Reloading the browser simply works since it’s going through the set of plugs that handle this problem. However, I would imagine that the alternative of having your LV processes run the code reloader per message is probably worse. It would be possible to add a Plug like setup to your LV, but the overhead would be far from ideal. I personally don’t really deal with this problem specifically since I write the core code, have tests that run against that and then wire it up with LV.
Using recompile in an iex shell does give you more control when to recompile, but I can imagine that runs against the dev userflow for some people.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









