hotwired / turbo-rails

Use Turbo in your Ruby on Rails app
https://turbo.hotwired.dev
MIT License
2.03k stars 305 forks source link

turbo_stream.remove_all Not generating proper selector for targets. #637

Closed t2 closed 1 week ago

t2 commented 1 week ago

When deleting an entity using Turbo, the remove_all stream action is not properly returning the selector in the stream. Please see below.

Gem: turbo-rails (2.0.5)
JS: @hotwired/turbo-rails@^8.0.4
@routine = Routine.find(params[:id])

respond_to do |format|
  format.turbo_stream do
    render turbo_stream: turbo_stream.remove_all(@routine)
  end

  format.html { redirect_to routines_path }
end
<turbo-stream action="remove" targets="#&lt;Routine:0x000000016b796988&gt;"></turbo-stream>
// Console output
DOMException: Failed to execute 'querySelectorAll' on 'Document': '#<Routine:0x0000000144d6f958>' is not a valid selector.
    at get targetElementsByQuery (http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58784:45)
    at get targetElements (http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58732:21)
    at HTMLElement.remove (http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58667:12)
    at Object.renderElement [as render] (http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58684:24)
    at http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58700:31
    at async HTMLElement.connectedCallback (http://localhost:3000/assets/application-esb-00291cc91fc91ec2365e55e77ee50f5725fda7f684dabce1c9176942cf33bde7.js:58688:9)