pfun

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

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

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

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.

Where Next?

Popular in Questions Top

greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement