Skip to content

Live Props

Data & Props

Live Props

Sometimes you may wish to keep a prop in sync with your server without any user interaction. Live props listen for your broadcast events and refresh the props those events affect, making them ideal for order statuses, unread counts, or dashboard metrics.

Live props are refreshed using partial reloads, so the client receives whatever your controller returns at that moment. Events may also carry the new values themselves.

Creating Live Props

To create a live prop, use Inertia::live()chain .live(inertia::on(&event)?) onto a prop, passing the broadcast event that should refresh it.

1use App\Events\OrderUpdated;
2 
3return Inertia::render('Orders/Show', [
4 'order' => Inertia::live(fn () => $order, on: new OrderUpdated($order)),
5]);
1use App\Events\OrderUpdated;
2 
3return Inertia::render('Orders/Show', [
4 'order' => Inertia::live(fn () => $order, on: new OrderUpdated($order)),
5]);
1use laravel::inertia::{self, Page, props};
2use laravel::prelude::*;
3 
4use crate::events::OrderUpdated;
5use crate::models::Order;
6 
7pub async fn show(Params(order_id): Params<i64>) -> laravel::Result<Page> {
8 Ok(inertia::render("Orders/Show", props! {
9 order => inertia::lazy(async move || Order::find(order_id).await)
10 .live(inertia::on(&OrderUpdated { order_id })?),
11 }))
12}
1use laravel::inertia::{self, Page, props};
2use laravel::prelude::*;
3 
4use crate::events::OrderUpdated;
5use crate::models::Order;
6 
7pub async fn show(Params(order_id): Params<i64>) -> laravel::Result<Page> {
8 Ok(inertia::render("Orders/Show", props! {
9 order => inertia::lazy(async move || Order::find(order_id).await)
10 .live(inertia::on(&OrderUpdated { order_id })?),
11 }))
12}

Inertia reads the channels from the event's broadcastOn()broadcast_on() method, and the client reloads the order prop whenever the event is broadcast.

Live props may be combined with deferred, once, optional, and always props. An optional live prop is only refreshed after the page has loaded it. Merge props may not be live.

1return Inertia::render('Orders/Show', [
2 'metrics' => Inertia::defer(fn () => $order->metrics())->live(on: new OrderUpdated($order)),
3]);
1return Inertia::render('Orders/Show', [
2 'metrics' => Inertia::defer(fn () => $order->metrics())->live(on: new OrderUpdated($order)),
3]);
1Ok(inertia::render("Orders/Show", props! {
2 metrics => inertia::defer(async move || order.metrics().await)
3 .live(inertia::on(&OrderUpdated { order_id })?),
4}))
1Ok(inertia::render("Orders/Show", props! {
2 metrics => inertia::defer(async move || order.metrics().await)
3 .live(inertia::on(&OrderUpdated { order_id })?),
4}))

Client Setup

Live props receive events through a transport, which you pass to the live option of createInertiaApp(). Inertia includes transports for Laravel Echo, pusher-js, and Action Cable, and subscribes and unsubscribes automatically as the user navigates.

Echo

Configure Echo as usual, then pass the echo() transport.

1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3import { configureEcho } from "@laravel/echo-vue";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});
1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3import { configureEcho } from "@laravel/echo-vue";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3import { configureEcho } from "@laravel/echo-react";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3import { configureEcho } from "@laravel/echo-react";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3import { configureEcho } from "@laravel/echo-svelte";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3import { configureEcho } from "@laravel/echo-svelte";
4 
5configureEcho({ broadcaster: "reverb" });
6 
7createInertiaApp({
8 live: echo(),
9 // ...
10});

You may pass a resolve callback to echo() to use a different Echo instance, such as one created with laravel-echo directly.

1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3 
4createInertiaApp({
5 live: echo({ resolve: () => window.Echo }),
6 // ...
7});

Pusher

The pusher() transport accepts a pusher-js client, which works with any Pusher-compatible server, such as Reverb. You are responsible for configuring the client, including channel authorization.

1import { pusher } from "@inertiajs/core/pusher";
2import Pusher from "pusher-js";
3 
4const client = new Pusher("pusher-app-key", {
5 // ...
6});
7 
8createInertiaApp({
9 live: pusher({ client }),
10 // ...
11});
1import { pusher } from "@inertiajs/core/pusher";
2import Pusher from "pusher-js";
3 
4const client = new Pusher("pusher-app-key", {
5 // ...
6});
7 
8createInertiaApp({
9 live: pusher({ client }),
10 // ...
11});

Action Cable

Rails applications may use the actionCable() transport for Action Cable. Pass a function that creates the consumer, so Inertia only opens the connection once a page subscribes, and never during server-side rendering.

1import { actionCable } from "@inertiajs/core/actionCable";
2import { createConsumer } from "@rails/actioncable";
3 
4createInertiaApp({
5 live: actionCable({ consumer: () => createConsumer() }),
6 // ...
7});
1import { actionCable } from "@inertiajs/core/actionCable";
2import { createConsumer } from "@rails/actioncable";
3 
4createInertiaApp({
5 live: actionCable({ consumer: () => createConsumer() }),
6 // ...
7});

AnyCable is also supported. Import createConsumer() from @anycable/web instead of @rails/actioncable.

Listening for Multiple Events

You may listen for more than one event to refresh a prop by passing an array of events to on:chaining .live(...) once for each event. Each event uses its own channels.

1return Inertia::render('Orders/Show', [
2 'order' => Inertia::live(fn () => $order, on: [
3 new OrderUpdated($order),
4 new OrderShipped($order),
5 ]),
6]);
1return Inertia::render('Orders/Show', [
2 'order' => Inertia::live(fn () => $order, on: [
3 new OrderUpdated($order),
4 new OrderShipped($order),
5 ]),
6]);
1Ok(inertia::render("Orders/Show", props! {
2 order => inertia::lazy(async move || Order::find(order_id).await)
3 .live(inertia::on(&OrderUpdated { order_id })?)
4 .live(inertia::on(&OrderShipped { order_id })?),
5}))
1Ok(inertia::render("Orders/Show", props! {
2 order => inertia::lazy(async move || Order::find(order_id).await)
3 .live(inertia::on(&OrderUpdated { order_id })?)
4 .live(inertia::on(&OrderShipped { order_id })?),
5}))

Props listening for the same event are refreshed together in a single request.

Channels

Live props listen on every channel your event broadcasts on. An event broadcasting on both orders.1 and orders therefore refreshes the prop whenever any order changes. You may specify a single channel instead using the channel argumentinertia::on_channel::<Event>(channel).

1return Inertia::render('Dashboard', [
2 'metrics' => Inertia::live(fn () => Metrics::today(), on: OrderUpdated::class, channel: new PrivateChannel('orders')),
3]);
1return Inertia::render('Dashboard', [
2 'metrics' => Inertia::live(fn () => Metrics::today(), on: OrderUpdated::class, channel: new PrivateChannel('orders')),
3]);
1use laravel::broadcast::Channel;
2 
3Ok(inertia::render("Dashboard", props! {
4 metrics => inertia::lazy(async || Metrics::today().await)
5 .live(inertia::on_channel::<OrderUpdated>(Channel::private("orders")?)),
6}))
1use laravel::broadcast::Channel;
2 
3Ok(inertia::render("Dashboard", props! {
4 metrics => inertia::lazy(async || Metrics::today().await)
5 .live(inertia::on_channel::<OrderUpdated>(Channel::private("orders")?)),
6}))

You may also pass an event class name instead of an instance, as long as its channels and broadcastAs() name don't depend on the event's data, since Inertia creates the event without calling its constructor.

1class OrderUpdated implements ShouldBroadcast
2{
3 public function broadcastOn(): PrivateChannel
4 {
5 return new PrivateChannel('orders');
6 }
7}
8 
9Inertia::live(fn () => $order, on: OrderUpdated::class);
1class OrderUpdated implements ShouldBroadcast
2{
3 public function broadcastOn(): PrivateChannel
4 {
5 return new PrivateChannel('orders');
6 }
7}
8 
9Inertia::live(fn () => $order, on: OrderUpdated::class);

inertia::on_channel::<Event>(channel) subscribes without constructing an event value using the event name generated by #[derive(Event)]. If your event overrides broadcast_as manually, use inertia::on(&event)? instead.

Each channel type is defined by its channel class or constructor:

1use Illuminate\Broadcasting\Channel;
2use Illuminate\Broadcasting\EncryptedPrivateChannel;
3use Illuminate\Broadcasting\PresenceChannel;
4use Illuminate\Broadcasting\PrivateChannel;
5 
6$channel = 'stats'; // public
7$channel = new Channel('stats'); // public
8$channel = new PrivateChannel('orders.1'); // private
9$channel = new PresenceChannel('room.1'); // presence
10$channel = new EncryptedPrivateChannel('orders.1'); // encrypted private
11 
12Inertia::live($value, on: $event, channel: $channel);
1use Illuminate\Broadcasting\Channel;
2use Illuminate\Broadcasting\EncryptedPrivateChannel;
3use Illuminate\Broadcasting\PresenceChannel;
4use Illuminate\Broadcasting\PrivateChannel;
5 
6$channel = 'stats'; // public
7$channel = new Channel('stats'); // public
8$channel = new PrivateChannel('orders.1'); // private
9$channel = new PresenceChannel('room.1'); // presence
10$channel = new EncryptedPrivateChannel('orders.1'); // encrypted private
11 
12Inertia::live($value, on: $event, channel: $channel);
1use laravel::broadcast::Channel;
2 
3let channel = Channel::public("stats")?; // public
4let channel = Channel::private("orders.1")?; // private
5let channel = Channel::presence("room.1")?; // presence
6 
7inertia::lazy(async || value)
8 .live(inertia::on_channel::<OrderUpdated>(channel));
1use laravel::broadcast::Channel;
2 
3let channel = Channel::public("stats")?; // public
4let channel = Channel::private("orders.1")?; // private
5let channel = Channel::presence("room.1")?; // presence
6 
7inertia::lazy(async || value)
8 .live(inertia::on_channel::<OrderUpdated>(channel));

Channels returned from broadcastOn()broadcast_on() follow the same rules, so wrap non-public channel names in the appropriate channel type.

1public function broadcastOn(): array
2{
3 return [
4 'stats', // public
5 new PrivateChannel('orders.1'), // private
6 ];
7}
1public function broadcastOn(): array
2{
3 return [
4 'stats', // public
5 new PrivateChannel('orders.1'), // private
6 ];
7}
1use laravel::broadcast::{Broadcast, Channel};
2 
3impl Broadcast for OrderUpdated {
4 fn broadcast_on(&self) -> laravel::Result<Vec<Channel>> {
5 Ok(vec![
6 Channel::public("stats")?,
7 Channel::private("orders.1")?,
8 ])
9 }
10}
1use laravel::broadcast::{Broadcast, Channel};
2 
3impl Broadcast for OrderUpdated {
4 fn broadcast_on(&self) -> laravel::Result<Vec<Channel>> {
5 Ok(vec![
6 Channel::public("stats")?,
7 Channel::private("orders.1")?,
8 ])
9 }
10}

Private, presence, and encrypted private channels are authorized through your channel routes (channels.phpsrc/routes/channels.rs) as usual.

Throttling

By default, each live prop refreshes at most once per second. You may change this default using the throttle option, in milliseconds, of echo(), pusher(), or actionCable().

1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/vue3";
2import { echo } from "@inertiajs/vue3/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/react";
2import { echo } from "@inertiajs/react/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});
1import { createInertiaApp } from "@inertiajs/svelte";
2import { echo } from "@inertiajs/svelte/echo";
3 
4createInertiaApp({
5 live: echo({ throttle: 2000 }),
6 // ...
7});

A prop may also define its own throttle.

1return Inertia::render('Dashboard', [
2 'metrics' => Inertia::live(fn () => Metrics::today(), on: new MetricsUpdated, throttle: 5000),
3]);
1return Inertia::render('Dashboard', [
2 'metrics' => Inertia::live(fn () => Metrics::today(), on: new MetricsUpdated, throttle: 5000),
3]);
1use laravel::prelude::*;
2 
3Ok(inertia::render("Dashboard", props! {
4 metrics => inertia::lazy(async || Metrics::today().await)
5 .live(inertia::on(&MetricsUpdated)?)
6 .throttle(5.seconds()),
7}))
1use laravel::prelude::*;
2 
3Ok(inertia::render("Dashboard", props! {
4 metrics => inertia::lazy(async || Metrics::today().await)
5 .live(inertia::on(&MetricsUpdated)?)
6 .throttle(5.seconds()),
7}))

Each prop is throttled separately, so a busy prop never delays the rest of the page. Events received during the throttle window are collected into a single request once the window ends. Manual reloads using router.reload() are never throttled.

A single action often broadcasts several events at once, so Inertia waits a few milliseconds before refreshing and collects every affected prop into one request.

Refreshes pause while the browser tab is hidden and resume when the user returns. You may disable this using the pauseWhenHidden option.

Broadcasting Values

By default, every listening page requests the new value from the server, so a dashboard open in a thousand tabs turns one event into a thousand requests. To avoid these requests, the event may broadcast the values itself using Inertia::broadcastProps()Broadcast::broadcast_props().

1class OrderUpdated implements ShouldBroadcast
2{
3 public function __construct(public Order $order) {}
4 
5 public function broadcastOn(): PrivateChannel
6 {
7 return new PrivateChannel("orders.{$this->order->id}");
8 }
9 
10 public function broadcastWith(): array
11 {
12 return [
13 'order_id' => $this->order->id,
14 ...Inertia::broadcastProps([
15 'order' => OrderResource::make($this->order),
16 ]),
17 ];
18 }
19}
1class OrderUpdated implements ShouldBroadcast
2{
3 public function __construct(public Order $order) {}
4 
5 public function broadcastOn(): PrivateChannel
6 {
7 return new PrivateChannel("orders.{$this->order->id}");
8 }
9 
10 public function broadcastWith(): array
11 {
12 return [
13 'order_id' => $this->order->id,
14 ...Inertia::broadcastProps([
15 'order' => OrderResource::make($this->order),
16 ]),
17 ];
18 }
19}
1use laravel::broadcast::{Broadcast, Channel};
2use laravel::event::Event;
3use serde_json::{Value, json};
4 
5#[derive(Event)]
6#[event(broadcast)]
7pub struct OrderUpdated {
8 pub order_id: i64,
9 pub status: String,
10}
11 
12impl Broadcast for OrderUpdated {
13 fn broadcast_on(&self) -> laravel::Result<Vec<Channel>> {
14 Ok(vec![Channel::private(format!("orders.{}", self.order_id))?])
15 }
16 
17 fn broadcast_props(&self) -> laravel::Result<Value> {
18 Ok(json!({ "order": { "id": self.order_id, "status": self.status } }))
19 }
20}
1use laravel::broadcast::{Broadcast, Channel};
2use laravel::event::Event;
3use serde_json::{Value, json};
4 
5#[derive(Event)]
6#[event(broadcast)]
7pub struct OrderUpdated {
8 pub order_id: i64,
9 pub status: String,
10}
11 
12impl Broadcast for OrderUpdated {
13 fn broadcast_on(&self) -> laravel::Result<Vec<Channel>> {
14 Ok(vec![Channel::private(format!("orders.{}", self.order_id))?])
15 }
16 
17 fn broadcast_props(&self) -> laravel::Result<Value> {
18 Ok(json!({ "order": { "id": self.order_id, "status": self.status } }))
19 }
20}

Inertia writes these values into the page without making a request. Keys are prop names. Values are resolved like page props, supporting resources, Arrayable objects, and closures, but not prop types such as Inertia::optional().Return a JSON object keyed by prop name.

Props that don't listen for the event ignore its values, and props the event carries no value for are reloaded as usual. A prop that is already being reloaded also ignores the value, since that request may return newer data.

Every subscriber of a channel receives the same payload, and channel authorization only runs when a user subscribes. Only broadcast values that every subscriber may see, and leave anything that depends on the user to a reload. Avoid exposing private model fields in broadcast payloads.

Tracking Refreshes

The useProp hook returns a prop's value and whether it is being refreshed, making it ideal for subtle loading indicators.

1<script setup>
2import { useProp } from "@inertiajs/vue3";
3 
4const { value: order, loading } = useProp("order");
5</script>
6 
7<template>
8 <div :class="{ 'opacity-50': loading }">
9 {{ order.status }}
10 </div>
11</template>
1<script setup>
2import { useProp } from "@inertiajs/vue3";
3 
4const { value: order, loading } = useProp("order");
5</script>
6 
7<template>
8 <div :class="{ 'opacity-50': loading }">
9 {{ order.status }}
10 </div>
11</template>
1import { useProp } from "@inertiajs/react";
2 
3export default () => {
4 const order = useProp("order");
5 
6 return <div className={order.loading ? "opacity-50" : ""}>{order.value.status}</div>;
7};
1import { useProp } from "@inertiajs/react";
2 
3export default () => {
4 const order = useProp("order");
5 
6 return <div className={order.loading ? "opacity-50" : ""}>{order.value.status}</div>;
7};
1<script>
2 import { useProp } from "@inertiajs/svelte";
3 
4 const order = useProp("order");
5</script>
6 
7<div class={order.loading ? "opacity-50" : ""}>
8 {order.value.status}
9</div>
1<script>
2 import { useProp } from "@inertiajs/svelte";
3 
4 const order = useProp("order");
5</script>
6 
7<div class={order.loading ? "opacity-50" : ""}>
8 {order.value.status}
9</div>

The hook also returns a loaded value, which is useful for live props that are also deferred.

Live Events

Inertia fires a cancelable live event before updating a live prop. Returning false skips the update, allowing you to show a "New data available" button instead. You may apply the update later using router.reload({ only: event.detail.props }).

1router.on("live", (event) => {
2 console.log(event.detail.props); // the props about to be refreshed
3 console.log(event.detail.channel); // { name, type }
4 console.log(event.detail.event); // the broadcast event name
5 console.log(event.detail.payload); // the broadcast payload
6 
7 return false;
8});
1router.on("live", (event) => {
2 console.log(event.detail.props); // the props about to be refreshed
3 console.log(event.detail.channel); // { name, type }
4 console.log(event.detail.event); // the broadcast event name
5 console.log(event.detail.payload); // the broadcast payload
6 
7 return false;
8});

Skipping the Current Connection

Inertia sends the socket ID as an X-Socket-Id header on same-origin requests, so the user who triggers a broadcast using toOthers()to_others() doesn't receive it.

1broadcast(new OrderUpdated($order))->toOthers();
1broadcast(new OrderUpdated($order))->toOthers();
1use laravel::broadcast;
2 
3broadcast::event(OrderUpdated { order_id })
4 .to_others()
5 .await?;
1use laravel::broadcast;
2 
3broadcast::event(OrderUpdated { order_id })
4 .to_others()
5 .await?;

You may provide your own socket ID using socketId.resolveUsing(), which takes precedence over the transport's. Passing null disables the header.

1import { socketId } from "@inertiajs/vue3";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);
1import { socketId } from "@inertiajs/vue3";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);
1import { socketId } from "@inertiajs/react";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);
1import { socketId } from "@inertiajs/react";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);
1import { socketId } from "@inertiajs/svelte";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);
1import { socketId } from "@inertiajs/svelte";
2 
3socketId.resolveUsing(() => mySocket.id);
4socketId.resolveUsing(null);

Custom Transports

You may pass any object implementing the LiveTransport interface to the live option, allowing you to receive events from your own WebSocket client, server-sent events, or a BroadcastChannel.

1import type { LiveTransport } from "@inertiajs/core";
2 
3const transport: LiveTransport = {
4 subscribe(channel, event, handler) {
5 // Called once per channel and event pair. Return a function that unsubscribes.
6 return () => {};
7 },
8 
9 // Optional. Lets Inertia send the socket ID so `toOthers()` works.
10 socketId: () => connection.id,
11 
12 // Optional. Inertia refreshes every live prop after a dropped connection
13 // returns, since events that fired while it was down never arrived.
14 onStatusChange(callback) {
15 return () => {};
16 },
17};
18 
19createInertiaApp({
20 live: transport,
21 // ...
22});
1import type { LiveTransport } from "@inertiajs/core";
2 
3const transport: LiveTransport = {
4 subscribe(channel, event, handler) {
5 // Called once per channel and event pair. Return a function that unsubscribes.
6 return () => {};
7 },
8 
9 // Optional. Lets Inertia send the socket ID so `toOthers()` works.
10 socketId: () => connection.id,
11 
12 // Optional. Inertia refreshes every live prop after a dropped connection
13 // returns, since events that fired while it was down never arrived.
14 onStatusChange(callback) {
15 return () => {};
16 },
17};
18 
19createInertiaApp({
20 live: transport,
21 // ...
22});

Channels arrive unprefixed with their type, such as { name: "orders.1", type: "private" }, so subscribe() should apply any prefix your broadcaster expects. A broadcaster that subscribes per channel rather than per event should join the channel on its first listener and leave it after its last. Since subscribe() runs during a page swap, avoid throwing from it, as an error aborts the swap.

The onStatusChange() callback receives a boolean indicating whether the connection is up. Inertia ignores repeated statuses and only acts when a dropped connection is restored.

1onStatusChange(callback) {
2 const handler = (state: string) => callback(state === "connected");
3 
4 connection.on("state_change", handler);
5 
6 return () => connection.off("state_change", handler);
7}
1onStatusChange(callback) {
2 const handler = (state: string) => callback(state === "connected");
3 
4 connection.on("state_change", handler);
5 
6 return () => connection.off("state_change", handler);
7}

Review the pusher.ts source for a reference implementation. It relies on a few internal helpers, such as prefixing channel names and counting the listeners on each channel, which your transport implements for its own broadcaster.

Channel Transports

Some broadcasters can't route messages by event name. Their transports may implement subscribeToChannel() instead, which is called once per channel. Inertia then reads the event name from each message's __inertia.event key. Review the actionCable.ts source for a reference implementation, which also uses internal helpers you'd write yourself.

1import type { LiveChannelTransport } from "@inertiajs/core";
2 
3const transport: LiveChannelTransport = {
4 subscribeToChannel(channel, handler) {
5 const stream = socket.subscribe(channel.name, handler);
6 
7 return () => stream.close();
8 },
9 
10 // Optional. Reads the event name from somewhere other than `__inertia.event`.
11 eventName: (payload) => (payload as { type?: string }).type,
12};
1import type { LiveChannelTransport } from "@inertiajs/core";
2 
3const transport: LiveChannelTransport = {
4 subscribeToChannel(channel, handler) {
5 const stream = socket.subscribe(channel.name, handler);
6 
7 return () => stream.close();
8 },
9 
10 // Optional. Reads the event name from somewhere other than `__inertia.event`.
11 eventName: (payload) => (payload as { type?: string }).type,
12};