Ensure response content is loaded before requestFinish is called. #1377
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously the response content was loaded asynchronously within the FetchRequest delegate. Consequently, the requestFinished callback was called prior this finishing. The requestFinished callback triggers the toggling of the busy attribute on
<html>/<turbo-frame>/<form>
, the triggering of the afterSubmit callback which toggles the disabled state of form submitters, and the the turbo:submit-end event.For clients with high latency, this could result in janky behaviour when the busy/disabled state is removed a noticeable time before the response is loaded and rendered.
This change removes this delay by ensuring the response is loaded and available prior to notifying the delegate and continuing execution of the Turbo behaviour.
Resolves #766 #884 #1202
Replaces #1039
Note that I explored other solutions, such as having the FetchRequest
await
the success handlers, etc. on the delegate. Unfortunately, because of the behaviours tied to therequestFinished
callback, this needs to be executed before the response is rendered by the other delegate callbacks, so that the various attribute updates on elements are processed before the PageSnapshot is taken for the cache, and before the existing DOM content is replaced as to not affect user callbacks.Ultimately, this solution practically resolves the issues, without impacting any other Turbo timings or behaviour.