I have the following component (it is a ViewComponent)
<turbo-frame id="subscription--state">
<% if subscribed %>
<%= button_to '👋 Leave', leave_community_path(id: community.title), class: 'button is-danger' %>
<% else %>
<%= button_to '😉 Join', join_community_path(id: community.title), class: 'button is-success'%>
<% end %>
</turbo-frame>
and in the controller
def join
community = Communities::Queries::FetchCommunity.call(slug: params[:id])
Communities::Commands::JoinCommunity.call(user_id: current_user.id, slug: params[:id])
render Communities::SubscriptionComponent.new(subscribed: true, community: community)
end
def leave
community = Communities::Queries::FetchCommunity.call(slug: params[:id])
Communities::Commands::LeaveCommunity.call(user_id: current_user.id, slug: params[:id])
render Communities::SubscriptionComponent.new(subscribed: false, community: community)
end
When the user joins or leaves, I do see request on the browser returning just the subscription component part which is great, but, it just doesn’t update the page.
I also see this on the logs:
17:49:26 web.1 | Started POST "/r/oddly_interesting/leave" for 127.0.0.1 at 2022-04-14 17:49:26 +0200
17:49:26 web.1 | Processing by CommunitiesController#leave as TURBO_STREAM
17:49:26 web.1 | Parameters: {"authenticity_token"=>"[FILTERED]", "id"=>"oddly_interesting"}
I dig a lot through it and I found that disabling the TURBO_STREAM mime type would solve the problem
Rails.application.config.after_initialize do
Mime::Type.unregister(:turbo_stream)
end
and LO AND BEHOLD, it works! doing the same thing now, without the turbo stream mime type replaces and updates the component on the app.
While this workaround is fine, I feel weird with it because just doesn’t feel right…I haven’t seen anywhere else on the internet someone doing the same thing (apart from the post where I found it) so I think I might have done some misconfiguration somewhere.
Has anyone seen this behavior? I’m not using turbo stream anywhere, just turbo-frames here and there
I’m using rails 7.0.2.3 and turbo-rails 1.0.1