Frame-or-page
Render a view as a Turbo Frame payload when the request came from a frame, or as a full page wrapped in a layout when the user loaded the URL directly. One view, one controller, no duplication.
This component is the declarative form of the frame-or-page recipe.
Basic Usage
{{-- resources/views/messages/edit.blade.php --}}
<hw:frame-or-page frame="modal" layout="dashboard">
<hw:form :action="route('messages.update', $message)" method="put">
<hw:field name="body" label="Message">
<hw:textarea :value="$message->body" auto-resize />
</hw:field>
<hw:button type="submit">Save</hw:button>
</hw:form>
</hw:frame-or-page>
- A request with
Turbo-Frame: modalrenders only<turbo-frame id="modal">…</turbo-frame>— Turbo swaps it into the matching frame in the receiving page. - A direct navigation renders the layout (
<x-layouts.dashboard>) wrapping the slot directly — no extra<turbo-frame>around the content. The standalone page is refresh-safe and bookmarkable, and any<turbo-frame>that should host modal/sidebar content lives in the layout itself.
The view itself stays oblivious to how it was requested.
Why no
<turbo-frame>around the slot on direct nav? A dashboard layout typically already hosts the receiving frame globally — e.g.<hw:modal frame="modal">renders a<turbo-frame id="modal">once per page. If the component also wrapped the slot in<turbo-frame id="modal">on direct nav, the page would carry two elements with the sameid: invalid HTML, and Turbo would aim subsequent navigations at the wrong frame.
Triggering the frame vs. the page
<a href="{{ route('messages.edit', $message) }}" data-turbo-frame="modal">Edit (modal)</a>
<a href="{{ route('messages.edit', $message) }}">Edit (page)</a>
The first link asks Turbo to scope the request to the modal frame, sending the Turbo-Frame
request header. The second link navigates normally; the layout renders the standalone page.
Pair with a frame host in your dashboard layout so the overlay opens automatically when the frame receives content. The
common hosts are <hw:modal frame="modal">, <hw:sheet frame="settings-panel">, and
<hw:drawer frame="drawer-panel">.
Frame-backed overlay instances
One Modal, Sheet or Drawer host in the layout can now receive several simultaneous openings. A link targeting the
canonical host frame (data-turbo-frame="modal", for example) starts a new instance with its own concrete Frame id;
the package allocates that id and carries it through Frame requests and submissions. A link inside the instance
without data-turbo-frame navigates within the current Frame instead of stacking another overlay. Explicitly targeting
the canonical id from inside an instance starts a new task on the stack. Do not author numbered hosts or generated ids.
Keep the view bound to the canonical id:
{{-- One shared host in the layout; no host per record or nested task. --}}
<hw:modal frame="modal" />
{{-- /customers/create responds to a Frame opening or direct page navigation. --}}
<hw:frame-or-page frame="modal" layout="layouts.app">
<hw:frame-or-page.frame target="modal">...</hw:frame-or-page.frame>
<hw:frame-or-page.page>...</hw:frame-or-page.page>
</hw:frame-or-page>
The .frame target="modal" branch still means the canonical host; the response wrapper uses the current
instance's concrete id. The request carries matching Turbo-Frame, X-Hotwire-Overlay-Host, and
X-Hotwire-Overlay-Instance headers. Invalid or inconsistent instance headers are rejected, and an unrelated host does
not select this view's frame branch. Regular Frame requests without an instance retain their existing behavior. These
headers correlate the render; they do not authorize access to a route. Laravel policies and validation still apply.
Default Frame navigation, pagination and forms inside an instance target its concrete Frame. If an element explicitly
sets data-turbo-frame="modal", it targets a new opening; omit it for navigation within the current one. Direct
navigation without Frame headers still renders the standalone page. Closing a child leaves the parent form and its
unsaved inputs in place; cache snapshots discard live instances. A full-page refresh is not a draft-preservation
operation: it can retire every open instance.
Frames nested inside an overlay retain their own Turbo-Frame id on requests and validation redirects. Those
requests also carry X-Hotwire-Overlay-Origin with the owning overlay's concrete Frame id; the host/instance headers
are reserved for requests targeting the overlay's own Frame, so a nested frame-or-page is not mistaken for the outer
overlay response. A form using track-frame-src can redirect validation errors back to its nested Frame.
request()->overlayOrigin() resolves the owning instance from either kind of request, so a form submitting from a
nested Frame still closes and returns to the right overlay; its own Turbo-Frame id would not identify the instance.
The origin is a correlation hint, not authorization.
For controller-side presentation decisions, see overlay detection with wasFromOverlay().
Returning to the initiating form
When a child creates a record for a parent form, wrap the destination field in
<hw:overlay-return> with a name local to that form, and select it with overlay-return on
the opening link. No document-wide field id or numbered Modal host is required:
<form>
<hw:overlay-return name="customer">
@include('customers._field')
</hw:overlay-return>
<hw:button as="a" href="{{ route('customers.create') }}" frame="modal" overlay-return="customer">
New customer
</hw:button>
<input name="notes" value="Draft in progress">
</form>
The link must belong to a form containing exactly one matching region; an absent or ambiguous region blocks the
opening. The package retains references to that form and region for this opening, so two sale forms can reuse the name
customer without cross-updating.
After creating the record, return the field's new contents and close only the submitting overlay:
$origin = $request->overlayOrigin();
return turbo_stream()
->returnFromOverlay($origin, view('customers._field', [
'customers' => $customers,
'selected' => $customer->id,
]))
->closeOverlay($origin)
->toast('success', 'Customer created');
The return replaces only the captured region's contents, emits native input and change events, and keeps the
parent form, its other values and its errors in place. closeOverlay uses the same concrete instance and normal
animated lifecycle; it never falls back to the top overlay. A duplicate or late Stream for a retired opening does
nothing. If the original form, opener or region was replaced while saving, the return does not rediscover a
different region with the same name: the child stays open with an alert, and the close action in that response is
suppressed. The record may already be saved; the user can close the child and select it in the current form.
Neither call submits the parent form or closes on every successful HTTP response; leaving the child open for "Save and continue" remains an explicit server decision. Validation errors that re-render a Frame keep its concrete id and do not run either Stream action.
For the family-specific response()->modal()/sheet()/drawer()->open(...) entries and composed
closeOverlay($origin), see the overlay responses recipe.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
frame |
string|object|null |
null |
One frame id. Accepts a string or any object resolvable via dom_id(). |
frames |
?iterable |
null |
A non-empty list of frame id strings or objects resolvable via dom_id(). |
layout |
?string |
null |
Blade component name (e.g. dashboard or layouts.dashboard) or class-string of the wrapper. |
overlay |
?string |
null |
Receiving family (modal, sheet, or drawer). Inferred when the served frame is one of those ids. |
overlay-side |
?string |
null |
Sheet side or Drawer direction. Modal does not accept this prop. |
overlay-size |
?string |
null |
Modal preset/CSS max-width or Sheet/Drawer CSS dimension. |
Provide exactly one of frame or frames. Empty ids and non-list frames values throw
InvalidArgumentException. Configuring more than one frame requires layout because direct navigation
and unknown frame headers need a page presentation. Arrays, Collections, and other iterables are accepted;
their keys must form a zero-based list.
When one frame is configured and layout is null, the component preserves frame-only mode: it always
renders the configured <turbo-frame>, regardless of the request header. This is useful for nested frames
that never need a standalone presentation.
Simple layout names resolve ergonomically: layout="dashboard" uses an existing dashboard component
when one is registered, otherwise it tries layouts.dashboard before falling back to the original value.
Names that already contain ., ::, or \ are used as-is. A blank layout is normalized to null and
therefore enables frame-only mode.
Lazy context content
Content directly inside the parent is shared. Put context-only content in the renderless
<hw:frame-or-page.frame> and <hw:frame-or-page.page> subcomponents:
{{-- resources/views/parks/topics/edit.blade.php --}}
<hw:frame-or-page frame="modal" layout="dashboard">
<hw:frame-or-page.page>
@include('parks._edit_header')
@include('parks._edit_navigation', ['active' => 'topics'])
</hw:frame-or-page.page>
@include('parks.topics._form')
<hw:frame-or-page.frame>
<hw:modal.close as="button">Cancel</hw:modal.close>
</hw:frame-or-page.frame>
<hw:frame-or-page.page>
@include('parks.topics._list')
</hw:frame-or-page.page>
</hw:frame-or-page>
These are class components whose shouldRender() decision runs before Blade evaluates their body.
Includes, queries, pushed assets, and other side effects in the discarded branch do not run. They emit no
wrapper element around a branch that does render, so HTML attributes such as class, id, and data-*
are rejected when that branch is active. Put those attributes on an element inside the branch. A discarded
branch is not evaluated, so its attributes are ignored together with its body.
The selection rules are:
- Shared parent content renders in both modes.
.framewithouttargetrenders for any configured frame when a frame is active..frame target="..."renders only for that active frame. The target must be declared by the parent'sframeorframesprop..pagerenders for direct navigation or aTurbo-Frameheader that does not match a configured frame.- With one frame and no layout, frame-only mode is always active and
.pageis not evaluated. - Contextual subcomponents use their nearest
<hw:frame-or-page>ancestor and throw when used without one.
The removed frameContent and pageContent named slots are not compatibility aliases. Replace them with
the lazy subcomponents; stale slots throw with migration guidance.
Multiple frame hosts
One route can serve different frame hosts while sharing its main content:
<hw:frame-or-page :frames="['modal', 'settings-panel']" layout="dashboard">
<hw:frame-or-page.frame target="modal">
<hw:modal.close as="button">Close modal</hw:modal.close>
</hw:frame-or-page.frame>
<hw:frame-or-page.frame target="settings-panel">
<hw:sheet.close as="button">Close sheet</hw:sheet.close>
</hw:frame-or-page.frame>
<hw:frame-or-page.page>
<x-page-heading>Edit message</x-page-heading>
</hw:frame-or-page.page>
@include('messages._edit-form')
<hw:frame-or-page.frame>
<hw:toast />
</hw:frame-or-page.frame>
</hw:frame-or-page>
Turbo-Frame: modal emits <turbo-frame id="modal">; Turbo-Frame: settings-panel emits
<turbo-frame id="settings-panel">. An opening from a shared overlay host emits the correlated concrete id instead,
while target="modal" or target="settings-panel" still selects the right branch. Direct navigation and unknown
headers render dashboard instead.
Forwarded attributes
When the component renders as a frame — that is, when the request came from a Turbo Frame OR
when layout is omitted — extra HTML attributes on <hw:frame-or-page> are forwarded to the
inner <hw:frame>. This includes native Turbo Frame attributes (src, loading,
target, refresh, autoscroll, …), frame aliases like lazy, advance, replace, poll,
view-transition, and arbitrary data-* hooks:
<hw:frame-or-page frame="messages" src="{{ route('messages.index') }}" loading="lazy" view-transition>
<div class="loading">Loading…</div>
</hw:frame-or-page>
Forwarding configures the frame emitted by this response. It does not configure a pre-existing frame host: Turbo's
FrameRenderer preserves that host and replaces only its children instead of copying response-frame attributes. For a
layout-owned host, enable the integration there, for example
<hw:modal frame="modal" view-transition>, <hw:sheet frame="settings-panel" view-transition>, or
<hw:drawer frame="drawer-panel" view-transition>.
Presentation per frame opening
The three overlay hosts are an exception to the normal attribute rule above: their controllers read the response
frame's data-overlay-* metadata before Turbo swaps its children. Declare the receiving family explicitly, then
specify only the settings this response owns:
{{-- Layout: a shared Modal host serves many routes. --}}
<hw:modal frame="modal" />
{{-- Customer create response (direct navigation still renders layouts.app). --}}
<hw:frame-or-page frame="modal" layout="layouts.app" overlay-size="sm">
<hw:modal.title>New customer</hw:modal.title>
...
</hw:frame-or-page>
<hw:button as="a" frame="modal" overlay-size="lg"> may hint at the size during loading.
The response wins for each property it declares; omitted properties keep the hint or the authored host default. Size
alone keeps the current side/direction. Subsequent frame navigations can update the same open instance. Closing or
abandoning a load restores host defaults, including defaults updated by a Turbo morph. Modal presets are sm, md,
lg, xl, full, auto; a CSS dimension sets max-width. Sheet sides are left, right, top, bottom; Drawer
directions are up, right, down, left (with top/bottom aliases). Changing axis moves the size to the matching
width/height variable. Invalid family, side and empty/unsafe size values throw in Blade.
For plain anchor and raw frame markup, use data-overlay-family, data-overlay-side, and data-overlay-size on the
link or response <turbo-frame>. A family must match the receiving controller. Presentation metadata is emitted only
in the frame branch; the standalone page does not carry overlay attributes. view-transition remains a host-level
choice: set it on <hw:modal>, <hw:sheet> or <hw:drawer> in the layout. A response cannot toggle the host's
view-transition controller for one opening by itself.
On direct navigation with a layout, the slot is rendered directly inside the layout component
with no surrounding <turbo-frame>, so frame-specific attributes like src / loading have no
target and are dropped. If you need a frame around your content on direct nav (rare — usually the
layout's host frame is enough), add an explicit <x-turbo::frame> inside the slot.
The component does not forward attributes to the layout. The layout is your own component — configure it the way you'd configure any other Blade layout:
- A route-specific layout component if the value is fixed per route. Keep that wrapper in the
layoutprop so frame requests can omit it:Do not wrapBLADE{{-- resources/views/components/layouts/message-edit.blade.php --}} <x-layouts.dashboard title="Edit message" :fixed-top="true"> {{ $slot }} </x-layouts.dashboard> {{-- resources/views/messages/edit.blade.php --}} <hw:frame-or-page frame="modal" layout="layouts.message-edit"> @include('messages._edit-form') </hw:frame-or-page>{{-- resources/views/components/layouts/message-edit.blade.php --}} <x-layouts.dashboard title="Edit message" :fixed-top="true"> {{ $slot }} </x-layouts.dashboard> {{-- resources/views/messages/edit.blade.php --}} <hw:frame-or-page frame="modal" layout="layouts.message-edit"> @include('messages._edit-form') </hw:frame-or-page><hw:frame-or-page>externally: an outer layout is evaluated before the component and therefore cannot be omitted from a frame response. @push/@stackfor cross-branch values (page title, breadcrumbs) — these survive both branches because Blade resolves the stack at render time.
Model-aware frame ids
When frame is an object, the component calls dom_id() (from
emaia/laravel-hotwire-turbo) to derive the id:
<hw:frame-or-page :frame="$message" layout="layouts.dashboard">
{{-- renders <turbo-frame id="message_42"> for a Message #42 --}}
</hw:frame-or-page>
This pairs naturally with dom_id($message) calls in your list views and stream responses, keeping
ids consistent across server-rendered, frame-targeted and Turbo Stream contexts.
Closing on success
When the form inside the frame submits successfully, the typical flow is: close the overlay and refresh the underlying page. Return a Turbo Stream:
public function update(Request $request, Message $message)
{
$message->update($request->validate([...]));
return turbo_stream()
->update($request->turboFrameId())
->toast('success', 'Saved');
}
See the frame-or-page recipe for the full pattern including dashboard layout setup and frame host wiring.
Use the request's concrete Frame id when closing just this instance with an empty stream. An empty update for the
canonical modal host does not close a child instance. A refresh stream affects the whole page and may discard the
parent's unsaved draft; use it only when that is intentional. Server-driven instance-aware close operations are covered
by the separate overlay response API.
Close event sources
The modal:closed, sheet:closed, and drawer:closed events bubble from the closing overlay root.
Read event.detail.source to distinguish:
| Source | What initiated the close |
|---|---|
user |
Escape, the backdrop, or an overlay close control. |
stream |
A targeted close command or an empty update to the overlay's Frame. |
programmatic |
A direct call to close(). |
cleanup |
Lifecycle cleanup, such as preparing the page for Turbo's cache. |
A Stream close does not imply a successful mutation. The event reports the source, not the outcome, and does not change the URL. If your application navigates in response to closing, ignore cleanup events.
Returning validation errors to the frame source
The visible page URL is not necessarily the URL that rendered a frame. A task board at /tasks may load an edit form
from /tasks/42/edit into modal, then submit the mutation to PUT /tasks/42. On validation failure, redirecting to
the board would make the form disappear because the response does not repopulate the modal frame.
Use track-frame-src on the form so the frame-rendering request URL is sent as _turbo_frame_src:
<hw:frame-or-page frame="modal" layout="dashboard">
<hw:form :action="route('tasks.update', $task)" method="put" track-frame-src>
{{-- fields --}}
</hw:form>
</hw:frame-or-page>
TurboFormRequest redirects validation failures back to that explicit, sanitized source. The
turbo--frame-src controller can provide the same context through a header when
the hidden input is unavailable, but the server-rendered input remains the deterministic primary source.
Influencing the overlay host from a frame payload
A common confusion: trying to configure shared chrome (a modal, sheet, drawer, or sidebar host) from within a view
that opens as a frame. That chrome lives in the host page's layout — it was already rendered with
its own settings before the frame request fired. The frame payload only swaps content inside the
matching <turbo-frame>; it cannot generally change elements outside the frame. Modal, Sheet and Drawer have two
explicit exceptions: accessible title/description links, and the presentation metadata
for side/size. Other root settings still belong to the host.
Three options, in order of how much they cost you:
- Use presentation metadata for size and side on a shared host. Other structural differences can use separate
hosts, such as
<hw:modal frame="modal-edit" :fixed-top="true">and<hw:sheet frame="settings-panel" side="right">, chosen bydata-turbo-frame. - Return targeted Streams for application-owned surrounding content when a response needs to change more than its
Frame. Target known unique elements, not the canonical
modalhost: an active generated instance has a different identity, and morphing the host does not configure that instance. Use the supported presentation metadata or an additional explicitly configured host for different overlay chrome; do not replace the active root to restyle it. - Render
<hw:modal frame="modal">or another frame host inside the view itself instead of relying on a shared host. More flexible per-view, but you lose the convenience of one host serving every link.
See also
- Frame-or-page recipe — the manual pattern this component encapsulates.
<hw:modal>,<hw:sheet>, and<hw:drawer>— frame hosts that receive dynamic content.<hw:frame>— render a regular Turbo Frame with ergonomic aliases likelazyandadvance.<hw:form>— thetrack-frame-srcvariant that preserves the originating frame URL.turbo--frame-srccontroller — client-side fallback for frame-aware redirects.