Module: InertiaJb::Renderer
- Defined in:
- lib/inertia_jb/renderer.rb
Overview
Prepended onto ActionView::TemplateRenderer to guarantee that a
.html.inertia template is never wrapped in a layout.
An .inertia template's body (see Handler) throws its props Hash back to
the controller before it produces any output, so a surrounding layout is
always discarded. Left alone, Rails would still resolve and compile the
controller's layout and emit phantom render_layout.action_view /
render_template.action_view events for it — their ensure blocks fire as
the throw unwinds the stack — whose timing absorbs the prop-building work,
polluting request logs and APM traces with a layout render that never
actually happened.
render_template is the one point where Rails has already resolved the
template (so we can see its handler) but has not yet looked up the layout
(find_layout runs one call deeper, in render_with_layout). Nulling the
layout here for our handler skips the lookup entirely — cleanly, without the
controller having to guess in advance which template an action will render.
This only affects our own templates. The real Inertia shell is applied later
by inertia-rails when it renders the inertia root template (an ERB
template) with config.layout, and plain .erb/.jb templates keep their
layouts exactly as in vanilla Rails.