wuemv/inertia-livewire
| Install | |
|---|---|
composer require wuemv/inertia-livewire |
|
| Latest Version: | v0.1.0 |
| PHP: | ~8.3.37 || ~8.4.28 || ^8.5.13 |
| Laravel: | 12 · 13 |
| License: | MIT |
| Last Updated: | Nov 27, 2026 |
| Links: | GitHub · Packagist |
inertia-livewire
Mount Livewire components inside the Inertia pages of a Laravel app.
Laravel renders the component on the server, the Inertia page receives its HTML as a prop, and a small Vue (or React) component puts it on the page and lets Livewire start it. Inertia keeps the page, the layout and the navigation; Livewire runs the component, with its own requests and its own DOM updates.
It suits apps whose core is Inertia but where some screens are easier to write as Livewire: settings and forms, admin screens, or plugins that third parties write in PHP and Blade, with no JavaScript build of their own.
return Inertia::livewire(BillingSettings::class, ['team' => $team->id], ['title' => 'Billing']);
<LivewireMount :component="livewire" class="rounded-lg border p-6" />
<LivewireMount component={livewire} className="rounded-lg border p-6" />
Requirements
- PHP 8.3.37, 8.4.28 or 8.5.13 and later: the newest security release of each PHP version
- Laravel 12.61.1 or 13.12 and later (earlier releases have a signed-URL flaw that lazy components rely on; Laravel 11 no longer gets security fixes)
- Livewire 4.4.8 or later (earlier releases have security advisories)
- Inertia 2 or 3 (
inertiajs/inertia-laravel) - Vue 3.3 or later, or React 18 or 19
Install
composer require wuemv/inertia-livewire
npm install @wuemv/inertia-livewire-vue # or @wuemv/inertia-livewire-react
Load Livewire in the Inertia root template, resources/views/app.blade.php. Livewire only adds its assets by itself to pages that render a component, and an Inertia page never does:
<head>
...
@livewireStyles
<x-inertia::head>...</x-inertia::head>
</head>
<body>
<x-inertia::app />
@livewireScripts
</body>
That is the root template of Inertia 3's starter kits. With the @inertiaHead and @inertia directives, the places are the same: @livewireStyles before @inertiaHead, @livewireScripts after @inertia.
Livewire brings Alpine: don't load another Alpine.
Usage
A page around one component
use Inertia\Inertia;
Route::get('/settings/billing', fn () => Inertia::livewire(
BillingSettings::class, // class, alias ('billing'), namespaced ('billing::settings') or view()
['team' => 7], // the component's mount() parameters: they stay on the server
['title' => 'Billing'], // the page's own props
'Settings/LivewirePage', // the page: default from config, 'LivewirePage'
));
The page receives its props and the component as livewire ({ key, html }):
<!-- resources/js/pages/Settings/LivewirePage.vue -->
<script setup lang="ts">
import { LivewireMount, type LivewireComponent } from '@wuemv/inertia-livewire-vue';
defineProps<{ title: string; livewire: LivewireComponent }>();
</script>
<template>
<h1>{{ title }}</h1>
<LivewireMount :component="livewire" class="p-6" />
</template>
// resources/js/pages/Settings/LivewirePage.tsx
import { LivewireMount, type LivewireComponent } from '@wuemv/inertia-livewire-react';
export default function LivewirePage({ title, livewire }: { title: string; livewire: LivewireComponent }) {
return (
<>
<h1>{title}</h1>
<LivewireMount component={livewire} className="p-6" />
</>
);
}
It gets the app's default layout like any other page (Inertia 3's starter kits set one in createInertiaApp({ layout })). Without a default layout, wrap it in yours.
A component inside any page
use Wuemv\InertiaLivewire\Facades\InertiaLivewire;
return Inertia::render('Dashboard', [
'stats' => $stats,
'activity' => InertiaLivewire::render(ActivityFeed::class, ['limit' => 20]),
]);
<LivewireMount :component="activity" />
<LivewireMount component={activity} />
The component renders when Inertia resolves the prop, so a partial reload that leaves it out (router.reload({ only: ['stats'] })) does not render it, and one that asks for it renders it anew.
A component that loads after the page
'chat' => InertiaLivewire::lazy(SupportChat::class, ['room' => $room->id]),
<LivewireMount :component="chat">
<template #placeholder><Spinner /></template>
</LivewireMount>
<LivewireMount component={chat} placeholder={<Spinner />} />
The prop is { key, url }. The browser fetches the HTML from a signed URL, which carries the component, its parameters and the user, encrypted:
- a browser cannot load another component or change the parameters;
- only the user it was made for can load it (or a guest, for a guest's page);
- it expires after
lazy_ttlseconds (one hour by default). Inertia keeps props in the browser history, so the back button can bring back an old URL:@error(React:onError) tells you when one has expired.
Parameters must be JSON-encodable: pass IDs, not models.
Events
From Livewire to the page:
$this->dispatch('invoice-paid', id: $invoice->id);
import { useLivewireEvent } from '@wuemv/inertia-livewire-vue';
import { router } from '@inertiajs/vue3';
useLivewireEvent('invoice-paid', ({ id }) => router.reload({ only: ['invoices'] }));
From the page to Livewire:
import { dispatch } from '@wuemv/inertia-livewire-vue';
dispatch('refresh-invoices', { team: 7 }); // #[On('refresh-invoices')] in the component
The React adapter has the same useLivewireEvent and dispatch: import them from @wuemv/inertia-livewire-react, and router from @inertiajs/react. In React, the callback can change from one render to the next; the latest one is called.
<LivewireMount>
| Vue | React | |
|---|---|---|
component |
component |
{ key, html } or { key, url }, from render(), Inertia::livewire() or lazy() |
html |
html |
plain HTML instead, for HTML from elsewhere |
as |
as |
the element, div by default |
#placeholder slot |
placeholder |
shown while a lazy component loads |
@loaded |
onLoaded |
called with the element once the component is in place |
@error |
onError |
called when a lazy component's request fails |
Other attributes (class or className, id, data-*) go on that element.
Livewire owns the element's content once it is there: while the key stays the same, the adapter never writes it again, so Livewire's own updates stay. Every render on the server gives a new key, and a new key stops the old component and mounts the new one: there is no need for a key of your own.
In React, the component stops when its element leaves the page. StrictMode (strictMode: true in createInertiaApp(), as Laravel's React starter kit has it) cleans up every effect once more in development, and <Activity> cleans them up while it hides a subtree, both with the element still in place: the component keeps running through them, as it does in production.
How it works
- Server:
Livewire::mount()renders the component, with the snapshot Livewire needs to run it, and the HTML travels in the Inertia prop. The key is a hash of that HTML. - Browser: Livewire's runtime is loaded once, by
@livewireScripts. The adapter puts the HTML into its element and callsAlpine.initTree()on it, which starts the components inside; when the element goes,Alpine.destroyTree()stops them. It never starts Livewire itself: starting it twice breaks it. - Before Livewire has started: a page's module scripts can mount components before Livewire starts on
DOMContentLoaded, andinitTree()does nothing useful then. The adapter leaves them in place, and Livewire's own start goes through the whole document and starts them with everything else.
Limits
- Use Inertia's links.
wire:navigatein an embedded component would fight Inertia's router. - With Inertia's SSR, the component's HTML is part of the server render; it starts once the page's JavaScript and Livewire have loaded.
- Components are separate from the page's Vue or React state: talk through events, or reload Inertia props.
- The back button brings a page back from Inertia's history, so its components start again as the server rendered them: what changed in them since (a count, unsaved form input) is gone. A lazy component is fetched again.
Configuration
php artisan vendor:publish --tag=inertia-livewire-config
| Key | Default | |
|---|---|---|
page |
LivewirePage |
the page Inertia::livewire() renders when none is given |
prop |
livewire |
the prop it passes the component in |
route.enabled |
true |
the endpoint for lazy components |
route.prefix |
inertia-livewire |
its path: /inertia-livewire/render |
route.middleware |
['web'] |
its middleware; keep the session in it |
lazy_ttl |
3600 |
how long a lazy URL is valid, in seconds |
Development
composer install && pnpm install
vendor/bin/pest # PHP: rendering, the page macro, the signed endpoint
composer lint # PHP: Pun's format check and lint (composer format fixes the style)
pnpm test # JavaScript: the core and the adapters, in jsdom
pnpm build && pnpm e2e # Chromium against a real Laravel + Livewire app (workbench/)
The end-to-end tests serve workbench/ with vendor/bin/testbench serve, and run the same page in Vue and in React (bundled before the tests, in StrictMode). Where Playwright cannot download its browser, point CHROMIUM_PATH at a Chromium.
License
MIT. See LICENSE.
Related Packages
Domion - Professional Architecture for Laravel with Automated Frontend & Auth In...
Seamless two-way reactive bridge between Livewire 4 and Vue 3 / React components...
A Laravel starter kit serving public pages with Blade and Livewire, and the admi...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v0.1.0 | ~8.3.37 || | ^12.61.1 || | MIT |