Hey Elixir folks 
Have you ever needed a chart, date picker, or code editor in LiveView and ended up writing JavaScript hooks just to connect everything?
How do you make sure your JavaScript components handle their lifecycle safely every time, especially across LiveView updates, navigation, and reconnects?
Aren’t lifecycle issues like missed cleanup, stale state, and duplicate event listeners some of the hardest bugs to track down?
That’s some of the reasons I started working on Xenia.
The idea is to write a small adapter describing how a JavaScript library starts, updates, and stops. Xenia takes care of the repetitive work: props, events, commands, form integration, and lifecycle cleanup.
I wanted to show what that actually looks like, so here are five examples from the examples app, with the code and rendered result side by side.
1. Making a JavaScript chart interactive
Imagine you’re building a dashboard with Chart.js. You want to pass data from LiveView, react when someone clicks a bar, or highlight a particular value from the server.
With Xenia, @data reaches the chart as a prop, clicking a bar triggers handle_event/3, and Xenia.push_to/4 sends commands to that particular chart.
2. Using a Web Component
Sometimes you find a Web Component and just want to use it in your LiveView page.
Here’s a rating component. Xenia forwards its props directly to the element, so there’s very little adapter code needed.
You can use it as a typed HEEx component and handle its events in LiveView.
3. Using a JavaScript widget in Phoenix forms
Date pickers are easy to display, but integrating them with Phoenix forms, validation, and error messages usually takes more work.
With Xenia, you can use a JavaScript widget with field={@form[:due]}, much like a regular <.input>.
Its value participates in form submission, phx-change validation, and form recovery after reconnecting.
4. Handling loading and errors
Some JavaScript libraries take time to initialize, especially when they’re loaded on demand.
Instead of showing an empty area, you can provide a <:loading> slot. If something fails, an <:error> slot appears.
A data-xenia-retry button can restart the component, while on_crash notifies LiveView.
5. Keeping JavaScript close to where it’s used
Not every JavaScript integration needs to be shared across an entire application.
If a widget belongs to just one page, its adapter can live alongside that page using LiveView’s colocated hooks, without registering it separately in app.js.
A few other things in Xenia 0.2.0
- Lazy loading:
lazy="visible" starts an island when it approaches the viewport.
- Keyboard shortcuts:
shortcuts={%{"mod+s" => "save"}} handles shortcuts while an island has focus.
- Shared values:
consumes: ["theme"] lets JavaScript components follow application-wide values.
- Connection awareness:
consumes: ["connection"] lets an island react when its LiveView disconnects.
- Server replies:
ctx.call is useful for search suggestions and autocomplete.
- Cleanup:
ctx.signal helps cancel requests and remove listeners.
- Developer tooling: TypeScript adapter types and
Xenia.Test for testing props, events, and commands.
Want to try it?
Add Xenia to your dependencies:
# mix.exs
{:xenia, "~> 0.2.0"}
Then run:
mix deps.get
# New application
mix xenia.install
# Existing Phoenix application
mix xenia.install --islands-only
There are now 36 examples in the examples app. Each has a runnable page where you can explore the integration and inspect how it’s implemented.
Examples: xenia/examples at main · uzaydurdu/xenia · GitHub
Documentation: Xenia v0.2.0 — Documentation
Hex: xenia | Hex
Source: GitHub - uzaydurdu/xenia: Keep Phoenix in charge, let JavaScript do what it does best: any JS library in LiveView with one small adapter. · GitHub
I’m curious about what other Phoenix developers are doing with JavaScript libraries.
Which libraries are you currently integrating with LiveView? Are there parts of that integration you find unnecessarily complicated?
I’d appreciate any feedback or suggestions. Thanks for taking a look!