Phoenix assigns not changing until I restart the server.
I have the below code.
defmodule GallowsWeb.PageController do
use GallowsWeb, :controller
def index(conn, _params) do
my_assigns = %{ produce: "pear", count: 3}
render conn, "index.html", my_assigns
end
end
If I render the page @produce is “pear” and @count is 3.
If I change the values of the my_assigns map, the value of @produce and @count do not change until I stop and restart the app.
Is this how this is meant to work?
Discovered something weird. If I manually refresh the page VERY quickly after making the change, it changes the value… but if I wait more than a second or so, it will never change until I try again and quickly refresh… Not sure what is going on here…
Those plugins are known to cause issues with phoenix code reloader. You should disable them for phoenix or make them compile in a different build folder or under a mix env that is not dev.
It has never really been discussed, but very often similar symptoms vanished after disabling compile on save in the editor. It’s hard to search for this, as it’s spreader through a plethora of topics and threads, sometimes accompanied by various other symptoms related to filesystem specifics.
It’s basically a race between the editor and phoenix. Phoenix does not remember which loaded module is how old, it just remembers which source files generates which modules. Now phoenix gets an event that source for module A has been saved, it checks the timestamp of Elixir.A.beam and since it has already been recompiled by the editor, phoenix concludes that the module is current, so it does not reload it. If though the editor uses a different folder/mix env, it won’t interfere with phoenix anymore.