You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found an inconsistency with the rendering of layouts and inline turbo stream responses, with the combination of the two currently being broken.
When rendering a turbo stream template action.turbo_stream.erb, it is rendered within a layout (e.g. application.turbo_stream.erb) if available. However when using render turbo_stream: turbo_stream.etc..., no layout is used. Furthermore, it is not possible to force a layout to be used by passing layout: true or layout: "application".
classTestController < ApplicationControllerdefturbo_template# Renders template with application layoutenddefturbo_template_layout_true# Renders template with application layoutrenderlayout: trueenddefturbo_inline# Renders with no layoutrenderturbo_stream: turbo_stream.append("container"){"Hello from inline Turbo Stream"}enddefturbo_inline_layout_true# Renders with no layout (!)renderturbo_stream: turbo_stream.append("container"){"Hello from inline Turbo Stream (layout: true)"},layout: trueenddefturbo_inline_explicit_layout# Renders with no layout (!)renderturbo_stream: turbo_stream.append("container"){"Hello from inline Turbo Stream (explicit layout)"},layout: "application"endend
You could override :turbo_stream renderer if you really need this:
# config/initializers/turbo_layout.rb# on load hook is to make sure to load this after Turbo adds its rendererActiveSupport.on_load(:action_controller)doActionController::Renderers.add:turbo_streamdo |source,options|
self.content_type=Mime[:turbo_stream]ifmedia_type.nil?render_to_string(inline: source,layout: options[:layout])endend
I've found an inconsistency with the rendering of layouts and inline turbo stream responses, with the combination of the two currently being broken.
When rendering a turbo stream template
action.turbo_stream.erb
, it is rendered within a layout (e.g.application.turbo_stream.erb
) if available. However when usingrender turbo_stream: turbo_stream.etc...
, no layout is used. Furthermore, it is not possible to force a layout to be used by passinglayout: true
orlayout: "application"
.I have created an example repo at https://github.com/spohlenz/turbo-stream-layouts (with the relevant changes in spohlenz/turbo-stream-layouts#8afd217d005f2f852bf27fb871ac4bbf7291d72a). This example uses Rails 7.2.0.beta3 and turbo-rails 2.0.6 but I have seen the same behavior on earlier Rails versions.
The text was updated successfully, but these errors were encountered: