Skip to content

Commit

Permalink
remove support for components in error pages
Browse files Browse the repository at this point in the history
It's possible to load those but requires injecting the LivePage env,
which is risky because a server error may happen due to internals or even
due to the components used in the pages, causing an endless loop.
So for now we won't load components due to the risk they impose but we can
revisit this if needed or if we find a safer approach.
  • Loading branch information
leandrocp committed Oct 12, 2023
1 parent 8324828 commit f68c6cb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 23 deletions.
7 changes: 1 addition & 6 deletions lib/beacon/loader/error_module_loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Beacon.Loader.ErrorModuleLoader do

def load_error_pages!(error_pages, site) do
error_module = Loader.error_module_for_site(site)
component_module = Loader.component_module_for_site(site)
layout_functions = Enum.map(error_pages, &build_layout_fn/1)
render_functions = Enum.map(error_pages, &build_render_fn(&1, error_module))

Expand All @@ -16,16 +15,12 @@ defmodule Beacon.Loader.ErrorModuleLoader do
use Phoenix.HTML
require EEx
import Phoenix.Component
unquote(Loader.maybe_import_my_component(component_module, render_functions ++ layout_functions))
require Logger

# One function per error page
unquote_splicing(layout_functions)

# One function per error page
unquote_splicing(render_functions)

# Catch-all for error which do not have an ErrorPage defined
# catch-all for error which do not have an ErrorPage defined
def render(var!(conn), var!(status)) do
_ = var!(conn)
Logger.warning("missing error page for #{unquote(site)} status #{var!(status)}")
Expand Down
17 changes: 0 additions & 17 deletions test/beacon/loader/error_module_loader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ defmodule Beacon.Loader.ErrorModuleLoaderTest do
end

setup %{conn: conn} do
component_fixture(site: @site)
:ok = Beacon.Loader.populate_layouts(@site)
:ok = Beacon.Loader.populate_error_pages(@site)
error_module = load_error_pages_module(@site)
Expand Down Expand Up @@ -70,22 +69,6 @@ defmodule Beacon.Loader.ErrorModuleLoaderTest do
assert error_module.layout(501, %{inner_content: error_page.template}) == {:safe, ["#custom_layout#", "error_501"]}
end

test "user-defined component in layout" do
layout = published_layout_fixture(template: ~S|<%= my_component("sample_component", val: 1 )%><%= @inner_content %>|, site: @site)
error_page = error_page_fixture(layout: layout, template: "error", status: 502, site: @site)
error_module = load_error_pages_module(@site)

assert error_module.layout(502, %{inner_content: error_page.template}) == {:safe, ["1", "error"]}
end

test "user-defined component in page" do
layout = published_layout_fixture(template: ~S|<%= @inner_content %>|, site: @site)
error_page = error_page_fixture(layout: layout, template: ~S|<%= my_component("sample_component", val: 1) %>|, status: 503, site: @site)
error_module = load_error_pages_module(@site)

assert error_module.layout(503, %{inner_content: error_page.template}) == {:safe, ["1", "error"]}
end

test "default error pages", %{conn: conn, error_module: error_module} do
expected =
~S"""
Expand Down

0 comments on commit f68c6cb

Please sign in to comment.