HEEX sigil override that injects LiveVue shared props and v-socket into every <.vue ...>
tag and LiveVue shortcut component tag.
Shared props are configured via config :live_vue, :shared_props and automatically
injected into all literal <.vue> tags and LiveVue shortcut component tags at compile time,
together with a builtin v-socket={get_in(assigns, [:socket])} attribute when one is not
already present. That keeps LiveView's change tracking working correctly (unlike the old
runtime-based shared_props which was removed in v1.0).
Configuration
In your config/config.exs:
config :live_vue,
shared_props: [
:flash,
{:current_user, :user},
{[:current_scope, :workspace], :workspace}
]Supported formats:
:atom- mapsassigns[:atom]to a prop namedatom{:source, :target}- mapsassigns[:source]to a prop namedtarget{[:nested, :path], :target}- mapsget_in(assigns, [:nested, :path])to a prop namedtarget
Setup
In your lib/my_app_web.ex, override the ~H sigil in contexts that use LiveVue component tags:
defp html_helpers do
quote do
# ... existing imports ...
use LiveVue
# Override ~H to inject shared props and v-socket into LiveVue tags
import Phoenix.Component, except: [sigil_H: 2]
import LiveVue.SharedPropsView, only: [sigil_H: 2]
end
endThis works by rewriting the HEEX template string at compile time, injecting shared props and
v-socket as explicit attributes before the template is compiled by Phoenix. This preserves
LiveView's reactivity since the props appear as regular template expressions.
Summary
Functions
Rewrites a HEEX template string, injecting shared props and v-socket into LiveVue tags.
Override for ~H that injects shared attrs and v-socket into LiveVue tags.