From f68c6cb0582b6cc1b002d7786982f4af8d4722d1 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Thu, 12 Oct 2023 17:58:54 -0400 Subject: [PATCH] remove support for components in error pages 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. --- lib/beacon/loader/error_module_loader.ex | 7 +------ test/beacon/loader/error_module_loader_test.exs | 17 ----------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/lib/beacon/loader/error_module_loader.ex b/lib/beacon/loader/error_module_loader.ex index 9770d851..785e2e8a 100644 --- a/lib/beacon/loader/error_module_loader.ex +++ b/lib/beacon/loader/error_module_loader.ex @@ -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)) @@ -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)}") diff --git a/test/beacon/loader/error_module_loader_test.exs b/test/beacon/loader/error_module_loader_test.exs index 7cc97ef6..88768dc0 100644 --- a/test/beacon/loader/error_module_loader_test.exs +++ b/test/beacon/loader/error_module_loader_test.exs @@ -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) @@ -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"""