tapioca icon indicating copy to clipboard operation
tapioca copied to clipboard

Tapioca v0.17.2 fails to generate signature for `AbstractController::Collector#turbo_stream`

Open olivier-thatch opened this issue 6 months ago • 3 comments

After upgrading Tapioca to 0.17.2 (or more recent) and regenerating the RBI for actionpack, the signature for AbstractController::Collector#turbo_stream is missing.

The AbstractController::Collector methods are dynamically generated based on Mime::SET: https://github.com/rails/rails/blob/v8.0.2/actionpack/lib/abstract_controller/collector.rb#L18-L20

The turbo-rails gem registers the turbo_stream format in a Rails initializer: https://github.com/hotwired/turbo-rails/blob/v2.0.16/lib/turbo/engine.rb#L102-L104

So it looks like something changed in 0.17.2 that causes the Rails initializer to no longer be executed.

This is problematic for us because we have code in controllers like this:

respond_to do |format|
  format.turbo_stream do
    render(turbo_stream: ...)
  end
end

and after regenerating the RBI for actionpack, the code above produces a Sorbet error:

Method `turbo_stream` does not exist on `ActionController::MimeResponds::Collector`

olivier-thatch avatar Jun 24 '25 19:06 olivier-thatch

Feels like it might be due to https://github.com/Shopify/tapioca/pull/293 but I think the dynamic generation would have the method's source location as AbstractController::Collector.

KaanOzkan avatar Jun 25 '25 17:06 KaanOzkan

That does seem to be the case:

AbstractController::Collector.instance_method(:turbo_stream).source_location
# => ["/Users/olivier/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/actionpack-8.0.2/lib/abstract_controller/collector.rb", 12]

olivier-thatch avatar Jun 25 '25 19:06 olivier-thatch

Until this is investigated users can manually define the method using a shim.

KaanOzkan avatar Jun 26 '25 13:06 KaanOzkan