I’m encountering weird behaviour with Turbo streams using Rails and I’m out of ideas what’s going on as I’ve never seen such a behaviour.
I have this simple one field form for changing a note. Wrapped in a turbo frame, it either displays the note and edit link, or form to simulate inline edit. My update action is also pretty simple.
The problem is, when I update the AR object, it has updated value after order.update, it has updated value in format block, but network response in the browser has old value => it seems like nothing changed. Magic happens when I add significant sleep on Rails side. For some reason, browser cancels first submit request and second submit request has updated value.
def update_note
order = Order.find(params[:id])
order.update(user_edit_params)
respond_to do |format|
format.turbo_stream do
order.reload
sleep 0.05
pp order.comment
render turbo_stream: turbo_stream.replace(
:order_note,
partial: 'orders/order_note',
locals: { order: order },
)
end
...
You can notice reload, sleep and pp calls as I’m trying to debug the issue.
Is there some kind of cache I’m unaware of? Rails log doesn’t suggest that it’s using any cache for template/partial rendering.
I’m running latest version of turbo-rails with Rails 7.2.x. I’ll appreciate any idea. It feels like I’m missing something very obvious even while writing this question but I’m out of ideas.
What happens if you make the request with curl? This would help narrow down whether it’s a browser issue (you may need to disable csrf protection). Worth trying another browser also.
Of course. I’ll also add full CURL command except cookies.
Everything seems all right to me. Output is correct TurboStream response, just including old DB value. You can see that comment payload is aaa but the response includes old aaabbb value.