Optimistic Link
Dispatches Optimistic UI updates when a Turbo-driven link is clicked. A single
controller on the <a> — no extra dispatch controller needed.
Identifier: optimistic--link
Loaded by: auto-loaded after php artisan hotwire:install; publish only to customize with
php artisan hotwire:controllers optimistic/link.
Usage — frame navigation with skeleton
<a href="/posts/42" data-turbo-frame="detail"
data-controller="optimistic--link">
View details
<hw:optimistic target="detail" action="update">
<div class="animate-pulse p-4">Loading...</div>
</hw:optimistic>
</a>
<turbo-frame id="detail"></turbo-frame>
The skeleton is painted into #detail the moment the link is clicked. The
real frame response replaces it.
Usage — method link with optimistic remove
The remove target should be the list item wrapper, not the link itself:
<li id="{{ dom_id($n) }}">
{{ $n->title }}
<a href="/notifications/{{ $n->id }}/dismiss"
data-turbo-method="delete"
data-controller="optimistic--link">
Dismiss
<hw:optimistic :target="dom_id($n)" action="remove" />
</a>
</li>
The <li> disappears immediately. The server's morph refresh confirms the
deletion; on failure it restores the row.
Click guard
The dispatch is only triggered when Turbo will actually handle the click. It is skipped for:
- Modifier clicks (Cmd/Ctrl/Shift/Alt) — the browser opens a new tab.
- Middle-click / non-primary buttons.
- Links with
target="_blank"or any non-_selftarget. - Links with
data-turbo="false". - Events whose
defaultPreventedis alreadytrue.
Notes
- Unlike
optimistic--form, noFormDatais passed —[data-field]population does not apply. - For form submissions use
optimistic--form. - For custom triggers use
optimistic--dispatchor import_dispatch.jsdirectly.