An Elixir library that embeds Svelte in Phoenix LiveView apps for client-side state and server-driven updates over websockets.
Overview
LiveSvelte lets Phoenix LiveView applications embed Svelte components while keeping real-time sync through the existing LiveView websocket. State changes still flow from the server, but Svelte handles DOM updates and local UI state instead of relying only on server-rendered HTML patches.
It supports end-to-end reactivity with LiveView, optional server-side rendering of Svelte, Tailwind and TypeScript for client assets, slot interoperability with LiveView, and a sigil-based DSL as an alternative to HEEx templates. Components live under assets/svelte and connect via props, hooks, and LiveView JavaScript interop helpers such as pushEvent and handleEvent.
Installation targets Phoenix 1.8+ projects and integrates Vite through phoenixvite, with an Igniter-based installer or manual steps. Development can hot-reload Svelte and CSS through an embedded Vite watcher; production SSR typically needs Node.js 19 or later, with Bun optional for package management and builds.
The package suits teams that want Svelte animations, scoped CSS, or richer client state without abandoning LiveView’s server-centric model. SSR can be toggled globally or per component when first paint or hydration behavior matters.
Key features
- LiveView websocket sync with Svelte components
- Optional server-side rendering for Svelte
- Vite and phoenixvite asset pipeline
- Sigil DSL alternative to HEEx
- Tailwind and TypeScript client support
- Slot interoperability with LiveView
- Components macro for JSX-like usage
- Dead view and preprocessing support
Use cases
- Complex local UI state in LiveView apps
- Chat and real-time interfaces with Svelte UI
- Svelte animations alongside server state
- Hybrid LiveView forms with Svelte widgets
- Scoped CSS in Phoenix full-stack projects