Module redefining in iex breaks live view


I am sure other people are familiar with the capability of redefining modules on the fly.
I noticed that if I do this on a live file that has a separate heex file, so no render/1 in the file afterwards the liveview breaks.
Same if I do this on a deplloyment or locally with in iex -S mix phx.server.
This works with regular ex files.

What I see in the logs is the following:

  redefining module XXXX.SessionsIndexLive (current version loaded from _build/dev/lib/betafi/ebin/Elixir.XXXX.SessionsIndexLive.beam)

  warning: render/1 was not implemented for XXXX.SessionsIndexLive.

  Make sure to either explicitly define a render/1 clause with a LiveView template:

      def render(assigns) do

  Or create a file at "./sessions_index_live.html.heex" with the LiveView template.

The file it is referring to exists.

Afterwards it turns into an error with this stack trace:

(xxxx 0.1.0) iex:2: XXXX.SessionsIndexLive.render/1
(phoenix_live_view 0.18.0) lib/phoenix_live_view/utils.ex:156: Phoenix.LiveView.Utils.to_rendered/2
(phoenix_live_view 0.18.0) lib/phoenix_live_view/channel.ex:809: Phoenix.LiveView.Channel.render_diff/3
(phoenix_live_view 0.18.0) lib/phoenix_live_view/channel.ex:446: Phoenix.LiveView.Channel.mount_handle_params_result/3
(phoenix_live_view 0.18.0) lib/phoenix_live_view/channel.ex:1010: Phoenix.LiveView.Channel.verified_mount/8
(phoenix_live_view 0.18.0) lib/phoenix_live_view/channel.ex:59: Phoenix.LiveView.Channel.handle_info/2
(stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
(stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
(stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

Is there a trick to redefining liveview, or is it not possible?

The latter mostly. When functions are compiled from templates (anything eex from external files, not just phoenix) those files are handled at the time the module is compiled. When you paste the module into iex this likely means relative file paths are off and in production – even if the paths would be correct – that the files referenced don’t exist in the first place. Both essentially mean the compilation won’t be successful in turning a file into a function.

1 Like