Skip to content

Waiting for turbo stream actions to finish executing #35

Closed
@janko

Description

@janko

We have the following desired scenario:

  1. user clicks a button
  2. we turn on loading animation
  3. send a turbo stream request via request.js
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions