Technology1 min read

Live Props for Real-Time Updates in Inertia.js v3.11

By · Published by Everything Blog

In short

The new architecture leverages server markers and client transports like Laravel Echo, Pusher, or Action Cable to reload designated properties when matching events arrive. To optimize system resources, reloads default to a throttle rate of once per prop per second and temporarily pause when browser tabs are hidden. Teams can also utilize broadcasted payloads to update page state instantly without issuing extra HTTP requests. Additionally, developers can track active refresh states through the introduced hook.

Key points

  • Using broadcast props allows direct state updates that eliminate additional client HTTP r…: Using broadcast props allows direct state updates that eliminate additional client HTTP reloads.
  • The useProp hook exposes current property values along with active loading and loaded sta…: The useProp hook exposes current property values along with active loading and loaded state flags.
  • Multiple properties assigned to the same broadcast channel are automatically grouped into…: Multiple properties assigned to the same broadcast channel are automatically grouped into a single request.

Sources checked by our analysis pipeline: 1

Inertia.js v3.11.0 and inertia-laravel v3.7.0 add live props. A live prop reloads when a broadcast event arrives, which updates the page without polling.

Inertia::live()

and->live()

mark a prop to refresh on a broadcast event- An

echo()

transport for Laravel Echo and Reverb, plus Pusher and Action Cable transports Inertia::broadcastProps()

sends new values inside the event, which skips the reload request- A

useProp()

hook reports when a prop is refreshing

Live Props

Pascal Baljet added live props to both the client and the Laravel adapter. On the server, wrap a prop with Inertia::live()

and pass the event that should refresh it. Inertia reads the channels from the event's broadcastOn()

method:

use App\Events\OrderUpdated; use Inertia\Inertia; return Inertia::render('Orders/Show', [ 'order' => Inertia::live(fn () => $order->fresh(), on: new OrderUpdated($order)), ]);

On the client, pass a transport to createInertiaApp()

. The echo()

helper uses the Echo instance that configureEcho()

sets up:

import { createInertiaApp } from '@inertiajs/vue3' import { echo } from '@inertiajs/vue3/echo' import { configureEcho } from '@laravel/echo-vue' configureEcho({ broadcaster: 'reverb' }) createInertiaApp({ live: echo(), })

When OrderUpdated

is broadcast, Inertia makes a partial…

Technology