Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await for FetchRequest delegate to handle response #1039

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanpdoyle
Copy link
Contributor

Closes #884

Despite the fact that Visit and FrameController are FetchRequest delegate classes that implement their delegate methods asynchronously on success (Visit.requestSucceededWithResponse and FrameController.requestSucceededWithResponse) and on failure (Visit.requestFailedWithResponse) and
FrameController.requestFailedWithResponse), the async FetchRequest.receive method doesn't use the await keyword to wait for those delegates to finish handling their callbacks.

This commit adds those await clauses.

@seanpdoyle
Copy link
Contributor Author

I'm hopeful that this resolves the underlying problems mentioned by #884. I'm not sure how to add test coverage for this. With TypeScript, we'd be able to enforce the FetchRequest delegate's interface, and have type hints to know that these methods are asynchronous and return Promise instances.

In the absence of that type checking, I'd really appreciate some guidance on how to add coverage to the test suite to guard against future regressions.

@seanpdoyle seanpdoyle force-pushed the issue-884 branch 2 times, most recently from 2a7c917 to d2478b5 Compare October 13, 2023 21:27
@armstrjare
Copy link

armstrjare commented Nov 14, 2023

I've added a comment on a suggested tweak which, in addition to the work you've done here, seems to resolve a related but different issue I've been having where the turbo-frame busy attribute is removed prior to the response body being downloaded and the frame being rendered, and there can be significant delay between this when there is a high latency connection and/or a large response body for the request.

I'm not quite sure on the best approach to test this in this project because my initial thought was to assert the timing/ordering of related events and DOM mutations to be as expected - but it doesn't seem trivial with the helper methods currently provided since these behaviours are tracked separately.

@seanpdoyle seanpdoyle force-pushed the issue-884 branch 2 times, most recently from 36a565d to 88c76e1 Compare November 29, 2023 17:48
@ggmueller
Copy link

I am seeing a similar problem as @armstrjare.

I have tested your update but it does not solve the issue for me. The busy attribute still is reset too early.

I am using a form to update a turbo-frame like this:

<form name="filter" method="get" data-turbo-frame="skill-results" class="mb-6">
                                <input type="text" id="search" x-on:input.debounce="$event.target.form.requestSubmit()"  placeholder="Suchen" name="SearchText" value="">
</form>
<turbo-frame id="skill-results" src="https://localhost:5001/Skills?SearchText=" complete="">
</turbo-frame>

The busy and aria-busy attributes are reset, when the response returns (before it is downloaded). It can be followed when throttling the network connection.

I suspect that, additionally to your fixes, also in frame_controller.js formSubmissionSucceededWithResponse has to be made async, and the call to frame.delegate.loadResponse() should be awaited.

Closes [hotwired#884]

Despite the fact that `Visit` and `FrameController` are `FetchRequest`
delegate classes that implement their delegate methods asynchronously on
success ([Visit.requestSucceededWithResponse][] and
[FrameController.requestSucceededWithResponse][]) and on failure
([Visit.requestFailedWithResponse][]) and
[FrameController.requestFailedWithResponse][]), the `async
FetchRequest.receive` method doesn't use the `await` keyword to wait for
those delegates to finish handling their callbacks.

This commit adds those `await` clauses.

[Visit.requestSucceededWithResponse]: https://github.com/hotwired/turbo/blob/c207f5b25758e4a084e8ae42e49712b91cf37114/src/core/drive/visit.js#L297
[FrameController.requestSucceededWithResponse]: https://github.com/hotwired/turbo/blob/c207f5b25758e4a084e8ae42e49712b91cf37114/src/core/frames/frame_controller.js#L210
[Visit.requestFailedWithResponse]: https://github.com/hotwired/turbo/blob/c207f5b25758e4a084e8ae42e49712b91cf37114/src/core/drive/visit.js#L311
[FrameController.requestFailedWithResponse]: https://github.com/hotwired/turbo/blob/c207f5b25758e4a084e8ae42e49712b91cf37114/src/core/frames/frame_controller.js#L215

[hotwired#884]: hotwired#884
@seanpdoyle seanpdoyle marked this pull request as draft January 30, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Progress Bar finishes prematurely
4 participants