My Liveview modal components are failing to open if they are called using live_patch within a span but work when called using a button with a handle-event.
I have a Liveview app that I upgraded to Phoenix 1.6.6. I have followed all of the directions laid out in this link. The app was fully functional before the upgrade:
Phoenix 1.5.x to 1.6 upgrade instructions
My app fails when I call certain modal components using a live_patch. I get this compilation error: “Stateful components must return a HEEx template (~H sigil or .heex extension)”
Yep, I’ve made sure that I replaced the ~L with ~H AND I’ve made sure that my stateful components have a div. I get this error with every single modal component whether it is stateful or stateless. I also get this error whether I put the template in an heex file or if it is defined within the .ex file.
BUT … I don’t get this error if I call the modal component via a button click that has a handle-event.
Here is what works and what doesn’t work:
FAILS (both Show and Save fail)
@impl true
def render(assigns) do
~H"""
<div id="resources">
...
<%= if @list_resources_action == "index" do %>
<span><%= live_patch "Show",
to: Routes.resourceform_index_path(@socket,
:show, resourceform) %></span><br>
<span><%= live_redirect "Save",
to: Routes.resourceform_save_resource_path(@socket,
:save, resourceform.id ) %></span>
<% end %>
...
</div>
"""
end
WORKS
If I call the modal component this way, then it works:
@impl true
def render(assigns) do
~H"""
<div id="authors">
...
<%= if @list_authors_action == "index" do %>
<div class="flex-shrink-0 w-10 h-10">
<button phx-click="show"
phx-target={@myself}
phx-value-id={author.id}>
<img class="w-full h-full" src="/images/show_button.png" title="Show">
</button>
</div>
<% end %>
...
</div>
"""
#*****************************************************************
# handle_event :show (glasses button)
#*****************************************************************
@impl true
def handle_event("show", %{"id" => id}, socket) do
{:noreply, push_redirect(socket, to: Routes.author_show_author_path(socket, :show_author, id), replace: true)}
end
end
I must be missing something. Are there a set of instructions for upgrading Liveview applications to Phoenix 1.6? Was I supposed to do something else to my modal components?