From e8409557a0dfbbd687d45718799579223014544c Mon Sep 17 00:00:00 2001 From: May Matyi Date: Wed, 6 Dec 2023 22:21:56 -0800 Subject: [PATCH 1/8] Fix live reload regression --- lib/live_view_native/layouts.ex | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/live_view_native/layouts.ex b/lib/live_view_native/layouts.ex index d03b041a..ba4eba5f 100644 --- a/lib/live_view_native/layouts.ex +++ b/lib/live_view_native/layouts.ex @@ -41,17 +41,18 @@ defmodule LiveViewNative.Layouts do |> compile_layout(template_path, opts) end - def compile_layout({_format, platform}, template_path, _opts) do + def compile_layout({_format, platform}, template_path, opts) do func_name = template_path |> Path.basename() |> Path.rootname() |> String.replace(".", "_") |> String.to_atom() + is_root_template? = "#{func_name}" == "root_#{platform.platform_id}" %{ class_tree: %{}, - template: File.read!(template_path), + template: layout_template(template_path, is_root_template?), eex_engine: platform.eex_engine, platform_id: platform.platform_id, render_function: func_name, @@ -62,6 +63,31 @@ defmodule LiveViewNative.Layouts do def compile_layout(_platform, _template_path, _opts), do: nil + def layout_template(template_path, is_root_template?) do + template_path + |> File.read!() + |> layout_template_with_live_reload(Mix.env()) + |> layout_template_with_csrf_token(is_root_template?) + end + + def layout_template_with_live_reload(template, :dev) do + """ + #{template} +