Description
We have the following desired scenario:
- user clicks a button
- we turn on loading animation
- send a turbo stream request via request.js
- remove loading animation when turbo stream actions are executed
The problem is, I couldn't figure out how to wait for turbo stream operations to finish. The most we can do is have an await response.text
, which if I understand correctly waits for the response body to be downloaded. But afterwards there are also DOM operations being executed as part of the turbo stream response, and that can take a long time in our case, as we have turbo stream commands with large chunks of HTML.
The response.renderTurboStream()
function which request.js runs does seem to finish after turbo stream DOM operations have finished. However, since request.js executes it internally and doesn't expose its promise, there doesn't seem to be a way to wait for it.
One solution might be to assign the promise returned by response.renderTurboStream()
to the response object, and provide a response getter, allowing users to wait for it.