From 434f88a694f9ab96150b2d1c9c7ef9ef41920e96 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Thu, 14 Mar 2024 15:30:17 -0400 Subject: [PATCH] Only pass `:request_id` option to Refresh Stream When rendering `` elements for broadcasting, **omit** the `:request_id` partial-local variable. When rendered partials utilize [Action View strict locals][], the extra variable raises an error: ``` unknown local :request_id ``` By omitting the `:request_id` from the `Turbo::Broadcastable#broadcast_rendering_with_defaults`, it isn't passed as part of partial rendering. Likewise, since `broadcast_refresh` never renders a partial, but instead builds an empty `` element, the `:request_id` local variable isn't necessary. [Action view strict locals]: https://guides.rubyonrails.org/action_view_overview.html#strict-locals --- app/models/concerns/turbo/broadcastable.rb | 2 +- test/dummy/app/views/messages/_message.html.erb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/turbo/broadcastable.rb b/app/models/concerns/turbo/broadcastable.rb index 29970dcd..6ca728b5 100644 --- a/app/models/concerns/turbo/broadcastable.rb +++ b/app/models/concerns/turbo/broadcastable.rb @@ -500,7 +500,7 @@ def broadcast_rendering_with_defaults(options) options.tap do |o| # Add the current instance into the locals with the element name (which is the un-namespaced name) # as the key. This parallels how the ActionView::ObjectRenderer would create a local variable. - o[:locals] = (o[:locals] || {}).reverse_merge!(model_name.element.to_sym => self, request_id: Turbo.current_request_id).compact + o[:locals] = (o[:locals] || {}).reverse_merge!(model_name.element.to_sym => self).compact if o[:html] || o[:partial] return o diff --git a/test/dummy/app/views/messages/_message.html.erb b/test/dummy/app/views/messages/_message.html.erb index f92ff187..82446f43 100644 --- a/test/dummy/app/views/messages/_message.html.erb +++ b/test/dummy/app/views/messages/_message.html.erb @@ -1 +1,3 @@ -

<%= message %>

\ No newline at end of file +<%# locals: (message:, profile: nil) %> + +

<%= message %>