LiveLift runs selected Phoenix LiveComponent interactions in the browser. Keep
your ~H template and handle_event/3; add use LiveLift and mark a supported
handler with @client true. The server still runs that handler on its own state
and sends the authoritative result. The surrounding page remains a regular
LiveView.
The Phoenix demo contains native LiveComponents and
legacy client views inside a regular LiveView. From examples/demo, run mix setup and
mix phx.server, then visit http://localhost:4000.
For an existing Phoenix app, follow the integration guide.
For the experimental two-line migration of a normal LiveComponent, see
Opt in a LiveComponent.
Run mix live_lift.audit to see which existing LiveComponent handlers fit the
current client subset and why others are blocked.
Run mix live_lift.test --cases test/live_lift_cases.json in your app's CI to
compare every marked handler in Elixir and Node; see the
native component guide.
Use component event telemetry to measure event frequency
and server handler time after opting in.
Add the experimental Hex package to your app's mix.exs:
{:live_lift, "~> 0.1.0-rc.1"}Use an ordinary stateful LiveComponent and mark a compatible handler:
defmodule MyAppWeb.Counter do
use Phoenix.LiveComponent
use LiveLift
def render(assigns) do
~H"""
<button phx-click="inc" phx-target={@myself}>{@count}</button>
"""
end
@client true
def handle_event("inc", _params, socket) do
{:noreply, update(socket, :count, &(&1 + 1))}
end
endRun the installer once, then build assets:
mix deps.get
mix live_lift.install
mix assets.buildThe installer wires the asset aliases and LiveSocket hook in a standard
Phoenix 1.8 app. The build generates generated_views.js and copies
live_lift_runtime.js into the app's assets/js. There is no import into a
LiveLift source checkout. For custom asset layouts, integrate manually as in
the integration guide.
The generated hook configuration in assets/js/app.js is equivalent to:
import {createClientHook} from "./live_lift_runtime.js"
import {views} from "./generated_views.js"
let liveSocket = new LiveSocket("/live", Socket, {
params: {_csrf_token: csrfToken},
hooks: {LiveLift: createClientHook(views)}
})The compile task discovers opted-in components in your app and generates one registry. Ignore the generated JavaScript files in Git. Mount the component in a LiveView template:
<.live_component module={MyAppWeb.Counter} id="counter" count={10} />LiveLift creates the phx-update="ignore" boundary for the opted-in component.
Marked events predict locally, travel through the normal LiveView channel, and
converge on the server result. Unmarked events stay on the server. The
native component guide describes the current
language subset and compile-time failures. Use mix live_lift.audit before
opting in a larger component.
For server-owned fields and versioned responses, see the sync contract.
The older LiveLift.Client, client_template, defclient, $click, and
LiveLift.View.island API still runs for existing apps and now emits migration
warnings. Its syntax and limits remain in the integration guide.
Elixir modules and templates outside the supported subset are not automatically
compiled for the browser.
For architecture, differences from Hologram, and limitations, see the comparison.
mix deps.get
mix test
cd assets && npm testThis release is experimental and currently supports Phoenix LiveView 1.2.x. See production limits and reproducible benchmarks before using it in a deployed app. For bundle overhead, server event measurements and the shortest setup, see performance and adoption. See the security model before sending client values to a server handler or including app state in an island.