I have a live_view that uses live_components to swap out the content of the page’s main content area depending on the selected item in the parent. I am having an issue where the live_component’s update/2 function’s params argument always contains ALL parameters including (what is in my world) non-new. I would expect mount/1
to be called once, and it is and update/2
to be called each time an parameter changes and only include the parameters that have changed since the last call to update
.
But I see update being passed all the params every time. Am i missing something, or dont i understand what constitudes “new”?
The render in the parent looks something like this:
@impl true
def render(assigns) do
selected_resource = assigns.selected_resource
page = selected_resource && page_module(selected_resource.type, selected_resource.page)
assigns = assign(assigns, :page, page)
~H"""
<div class="flex h-screen w-screen bg-green">
<.side_menu
project={@project}
selected_tab={@selected_tab}
search_active={@search_active}
selected_resource={@selected_resource}
/>
<div class="flex-1">
<.async_result :let={resource} assign={@resource}>
<:loading>
Loading...
</:loading>
<:failed>
Failed to fetch resource
</:failed>
<.live_component
:if={@page}
id="page"
module={@page}
resource={resource}
resource_id={@selected_resource}
project_id={@project_id}
current_user={@current_user}
timezone={@timezone}
/>
</.async_result>
</div>
</div>
"""
end
My live_component update function does:
Map.keys(params) #=> [:id, :resource, :current_user, :resource_id, :timezone, :project_id]
And outputs the same keys every time update is called.