Error using `on_mount Sentry.LiveViewHook` for child LiveView
benregn opened this issue · 0 comments
Environment
Elixir 1.16.3
Phoenix 1.7.12
Phoenix LiveView 0.20.14
Sentry 10.6.1
Steps to Reproduce
I added the on_mount Sentry.LiveViewHook
to MyAppWeb.live_view
so it applies to all my LiveViews. I also have a LiveView that does use MyAppWeb, :live_view
that I also embed in a dead view via live_render
.
Repro one-file: https://gist.github.com/benregn/2e64c494ac8db44c0d3aa48660182d93
Expected Result
On navigating to the page with the embedded LiveView, I expect to see no errors.
Actual Result
On navigating to the page with the embedded LiveView, I see this error:
[error] Sentry.LiveView.on_mount hook errored out: ** (RuntimeError) cannot attach hook with id Sentry.LiveViewHook on :handle_params because the view was not mounted at the router with the live/3 macro
Workaround
I made this wrapper to alleviate the problem in my app:
defmodule SentryLiveViewHookWrapper do
def on_mount(_arg, :not_mounted_at_router, session, socket) do
{:cont, socket}
end
def on_mount(:default, params, session, socket),
do: Sentry.LiveViewHook.on_mount(:default, params, session, socket)
end