Phoenix LiveView cannot verified_mount/4 in MIX_ENV=prod

Hey there,

since I updated some dependencies 7 days ago, my live view does not work when phoenix is running in prod mode. However when I run phoenix with MIX_ENV=dev everything works fine. At the same time I switched from Elixir 1.8.x to 1.9.1 for tinkering around with “mix release”. Before those updates it worked in both environments.

I get two error message. This is the error message from the browser console:

TypeError: this.loader is null

And here the error message from the console that will be repeated untill I switch the site:

20:39:02.786 [error] GenServer #PID<0.917.0> terminating
** (MatchError) no match of right hand side value: %{"session" => "SFMyNTY.g3QAAAACZAAEZGF0YWgCYQJ0AAAABmQAAmlkbQAAAAxwaHgtUzlRQlp3OXVkAApwYXJlbnRfcGlkZAADbmlsZAAIcm9vdF9waWRkAANuaWxkAAZyb3V0ZXJkABdFbGl4aXIuSmFydmlzV2ViLlJvdXRlcmQAB3Nlc3Npb250AAAAAWQAB3VzZXJfaWRhAWQABHZpZXdkABlFbGl4aXIuSmFydmlzV2ViLkl0ZW1MaXZlZAAGc2lnbmVkbgYA2bfEjW0B.JvGoJJb2FABPHpF7_-neiEXwmnLnT4mWeOL1m-_zUO8", "static" => nil}
    (phoenix_live_view) lib/phoenix_live_view/channel.ex:451: Phoenix.LiveView.Channel.verified_mount/4
    (phoenix_live_view) lib/phoenix_live_view/channel.ex:28: Phoenix.LiveView.Channel.handle_info/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:mount, Phoenix.LiveView.Channel}
State: {%{"session" => "SFMyNTY.g3QAAAACZAAEZGF0YWgCYQJ0AAAABmQAAmlkbQAAAAxwaHgtUzlRQlp3OXVkAApwYXJlbnRfcGlkZAADbmlsZAAIcm9vdF9waWRkAANuaWxkAAZyb3V0ZXJkABdFbGl4aXIuSmFydmlzV2ViLlJvdXRlcmQAB3Nlc3Npb250AAAAAWQAB3VzZXJfaWRhAWQABHZpZXdkABlFbGl4aXIuSmFydmlzV2ViLkl0ZW1MaXZlZAAGc2lnbmVkbgYA2bfEjW0B.JvGoJJb2FABPHpF7_-neiEXwmnLnT4mWeOL1m-_zUO8", "static" => nil}, {#PID<0.915.0>, #Reference<0.798463413.1772879880.169990>}, %Phoenix.Socket{assigns: %{}, channel: Phoenix.LiveView.Channel, channel_pid: nil, endpoint: JarvisWeb.Endpoint, handler: Phoenix.LiveView.Socket, id: nil, join_ref: "1", joined: false, private: %{}, pubsub_server: Jarvis.PubSub, ref: nil, serializer: Phoenix.Socket.V2.JSONSerializer, topic: "lv:phx-S9QBZw9u", transport: :websocket, transport_pid: #PID<0.915.0>}}
20:39:02.787 [error] an exception was raised:
    ** (MatchError) no match of right hand side value: %{"session" => "SFMyNTY.g3QAAAACZAAEZGF0YWgCYQJ0AAAABmQAAmlkbQAAAAxwaHgtUzlRQlp3OXVkAApwYXJlbnRfcGlkZAADbmlsZAAIcm9vdF9waWRkAANuaWxkAAZyb3V0ZXJkABdFbGl4aXIuSmFydmlzV2ViLlJvdXRlcmQAB3Nlc3Npb250AAAAAWQAB3VzZXJfaWRhAWQABHZpZXdkABlFbGl4aXIuSmFydmlzV2ViLkl0ZW1MaXZlZAAGc2lnbmVkbgYA2bfEjW0B.JvGoJJb2FABPHpF7_-neiEXwmnLnT4mWeOL1m-_zUO8", "static" => nil}
        (phoenix_live_view) lib/phoenix_live_view/channel.ex:451: Phoenix.LiveView.Channel.verified_mount/4
        (phoenix_live_view) lib/phoenix_live_view/channel.ex:28: Phoenix.LiveView.Channel.handle_info/2
        (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
        (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

To get more information I debugged Phoenix.LiveView.Channel.verified_mount/4 with iex. The given function paramter “params” contains no key url or params. Therefore the following line fails -> failing line.

And now the big quiz question: Why does this fail only in prod environment (MIX_ENV=prod) but not in dev environment (MIX_ENV=dev)? Or where are the keys “url” and “params”?

Github - My phoenix project

Here the updated dependencies: mix.lock changes

Does it fail in production also when running locally? Or only on your production servers? Have you tried removing _build and starting fresh?

Btw, If it does happen locally and you can reproduce it by going back and forth between two commits, I would love to take a look at it. Cache bugs are not supposed to happen. I could sign a NDA if necessary.

Thanks for your reply.

It occurred first on the production server and afterwards I was able to reproduce the error with the steps mentioned in my intial post. I also deleted the _build folder. In the multi-stage docker image that happens by default.

Meanwhile I found the issue. I changed the build procedure and removed by mistake “mix phx.digest”. In addition I updated the phoenix_live_view version. Together those actions lead to a mismatch of the JavaScript stuff and the phoenix_live_view backend.

embarrassing :flushed: