Skip to content

Instantly share code, notes, and snippets.

@benregn
Last active June 15, 2024 18:27
Show Gist options
  • Save benregn/2e64c494ac8db44c0d3aa48660182d93 to your computer and use it in GitHub Desktop.
Save benregn/2e64c494ac8db44c0d3aa48660182d93 to your computer and use it in GitHub Desktop.
Bug reproduction for Elixir Sentry LiveViewHook
Application.put_env(:sample, Example.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
)
Mix.install([
{:plug_cowboy, "~> 2.5"},
{:jason, "~> 1.0"},
{:phoenix, "~> 1.7.0"},
{:phoenix_live_view, "~> 0.20"},
{:sentry, "~> 10.0"},
{:hackney, "~> 1.19"},
])
defmodule Example.ErrorView do
def render(template, _), do: Phoenix.Controller.status_message_from_template(template)
end
defmodule SentryLiveViewHookWrapper do
def on_mount(_arg, :not_mounted_at_router, _session, socket), do: {:cont, socket}
def on_mount(:default, params, session, socket),
do: Sentry.LiveViewHook.on_mount(:default, params, session, socket)
end
defmodule Example.FooLive do
use Phoenix.LiveView
on_mount Sentry.LiveViewHook
@impl true
def render(assigns) do
~H"""
<div>I'm being live_rendered!</div>
"""
end
end
defmodule Example.PageController do
use Phoenix.Controller
use Phoenix.Component
def page(conn, _params) do
assigns = %{conn: conn}
rendered = ~H"""
I'm a controller! <br><%= live_render(@conn, Example.FooLive, id: "live-render-id") %>
"""
content = Phoenix.HTML.Safe.to_iodata(rendered)
text(conn, content)
end
end
defmodule Example.Router do
use Phoenix.Router
import Phoenix.LiveView.Router
pipeline :browser do
plug(:accepts, ["html"])
end
scope "/", Example do
pipe_through(:browser)
get("/", PageController, :page)
end
end
defmodule Example.Endpoint do
use Phoenix.Endpoint, otp_app: :sample
socket("/live", Phoenix.LiveView.Socket)
plug(Example.Router)
end
{:ok, _} = Supervisor.start_link([Example.Endpoint], strategy: :one_for_one)
Process.sleep(:infinity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment