Helper functions for working with PhoenixKit layouts efficiently.
Performance: Avoiding Unnecessary Layout Diffs
When using the dashboard layout, do not pass all assigns:
# ❌ BAD - triggers layout diff on ANY assign change
<PhoenixKitWeb.Layouts.dashboard {assigns}>
# ✅ GOOD - only passes assigns the layout uses
<PhoenixKitWeb.Layouts.dashboard {dashboard_assigns(assigns)}>The dashboard_assigns/1 function extracts only the assigns the layout
actually needs, preventing unnecessary network traffic when other assigns
(like application-specific data) change.
Summary
Functions
Extracts only the assigns needed by the dashboard layout.
Returns the list of assign keys used by the dashboard layout.
Functions
Extracts only the assigns needed by the dashboard layout.
Use this to avoid unnecessary layout diffs when other assigns change:
def render(assigns) do
~H"""
<PhoenixKitWeb.Layouts.dashboard {dashboard_assigns(assigns)}>
<.my_content data={@data} />
</PhoenixKitWeb.Layouts.dashboard>
"""
endThis prevents the layout from re-rendering when assigns like @data
change, since the layout doesn't use @data.
Performance Impact
Without this optimization, a LiveView receiving 7 updates/second can send ~84KB/sec of redundant layout HTML. With this optimization, layout diffs only occur when layout-relevant assigns actually change.
@spec dashboard_layout_keys() :: [atom()]
Returns the list of assign keys used by the dashboard layout.
Useful for debugging or extending the layout with custom assigns.