Skip to main content
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 the Inertia::live() method and pass the event that should refresh it.
Inertia reads the channels from the event’s broadcastOn() 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.

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.
You may pass a resolve callback to echo() to use a different Echo instance, such as one created with laravel-echo directly.

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.

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.
AnyCable is also supported. Import createConsumer() from @anycable/web instead of @rails/actioncable.

Listening for Multiple Events

You may pass an array of events to refresh a prop from more than one event. Each event uses its own channels.
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 pass the channel argument to listen on a specific channel instead.
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.
A bare string is a public channel, and each channel class defines its own type.
Channels returned from broadcastOn() follow the same rules, so wrap non-public channel names in the appropriate channel class.
Private, presence, and encrypted private channels are authorized through your channels.php routes 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().
A prop may also define its own throttle.
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().
Inertia writes these values into the page without making a request. Keys are prop names, using dot notation for nested props. Values are resolved like page props, so resources, Arrayable objects, and closures all work, but prop types such as Inertia::optional() do not. 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. Prefer resources over models, since a model broadcasts every attribute that isn’t $hidden.

Tracking Refreshes

The useProp hook returns a prop’s value and whether it is being refreshed, making it ideal for subtle loading indicators.
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 }).

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() doesn’t receive it.
You may provide your own socket ID using socketId.resolveUsing(), which takes precedence over the transport’s. Passing null disables the header.

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.
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.
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.