-
Notifications
You must be signed in to change notification settings - Fork 432
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
Turbo uses Fetch which doesn't support progress #652
Comments
The current workaround is to use XMLHttpRequest.upload instead of fetch.
see: Upload progress bar using XHR (Fetch alternative) Note: I've read that XMLHttpRequest for upload on ReactNative runs 10x slower than fetch. So if using for a mobile app you will want to test to see this slow issue applies to mobile web in general, or just ReactNative. |
Thanks for the reply. I read the article and it's basically the same implementation I talked about using Axios on the first post but with XMLHttpRequest instead. It doesn't really answer the question because on form validation error 422 it will still cancel the Turbo visit and on HTTP 200 aswell. Right now this is what I do but with Axios
It would be nice to
Any solution? From my point of view, if Turbo wasn't using fetch, I could just read the progress from this and not alter any behavior.
Thanks in advance |
Ah, sorry my response was only focused on upload progress, I didn't address the validation error loss
I believe it's possible to execute a Turbo#visit without sending another request by setting the } else if (response.status === 301 || response.status === 302) {
// It seems the browser is hiding the 302 to Javascript or at least that we can't catch it even
// with follow redirect disabled. Leaving here in case it ever changes...
- Turbo.visit(response.headers.location, {action: "replace"});
+ Turbo.visit(response.headers.location, {action: "replace", response: response.data});
});
Fetch is at the core of Turbo Drive (caching). You could disable turbo drive and still use turbo-frames/turbo-streams if your main reasons for using turbo focus around turbo-frames or turbo-streams. From the turbo handbook
Turbo.session.drive = false FYI, you might be interested in #445 and hotwired/turbo-rails#367. While the concept is focused on "breaking out of turbo-frames using the response from the server", there might be a similar approach to "breaking out of turbo response from the response of the server". |
@tleish Thanks for the quick response. I tried doing instead of this
This
There is no crash but the response is not used because there is no form validation errors shown unlike in the first scenario |
I'm not sure I understand. Are you saying the fetch response includes the error, but when using it inside a Turbo.visit, it doesn't render the errors? What am I missing? |
Yes i'm saying when doing Turbo.visit(location.href, {action: "replace", response: response.data}); response.data includes de validation errors in the "HTML" string but they are not showing on my browser. When I do this instead it is shown properly
It feels like |
Looks like turbo expects the response to option in a specific format. You could try: const visitResponse = {
statusCode: response.status,
redirected: false,
responseHTML: response.data
}
Turbo.visit(location.href, {action: "replace", response: visitResponse}); |
@tleish Works perfectly!! Thank you. I'm happy with this workaround for now but I still think Fetch is lacking in terms of functionality :) |
Glad you figured out it out. Sorry, can't help with browser fetch lacking in progress reporting. |
@tleish I hadn't seen sooner, while it does work in generates javascript errors: |
What version of turbo are you using? |
It seems all my Javascript is being reloaded because Google Map complains aswell to be already loaded |
I know this error can happen when the turbo library is loaded twice. I'd need to see the full HTML original page and the responding page to help further. |
I tested on a blank page with only my javascript included and an empty body. Then I ran in my chrome console the following
where the script is the same javascript and I get the same error. The only thing I have in my js file is
Edit I woud like to add: if I change the HTTP Code from 422 to 200, it doesn't use the response html. It makes a new GET and use that response. Why? |
There's a conflict with the way the javascript loads that causing the turbo library to be loaded twice. This is it working without any errors: https://codepen.io/tleish/pen/dymmMKg
Not sure. |
If you have more question as you try and figure this out, I suggest closing this issue and using the community forums in asking for general help: |
Thanks for the help, I will head to the discuss website. Just want to add that your exemple is flawed because the My Rails application share the same Edit: Linking issue https://discuss.hotwired.dev/t/turbo-visit-with-html-response-generates-error-an-is-inconsistent/4348
|
Hi,
I'm here to ask for a new feature. I have a project where I can submit heavy files and I would like to be able to follow the progress. An easy way would be to catch the form submit event, cancel it, repeat it by Ajax and follow the progress.
Pseudo code of something working (partially) with Axios
The only issue with this code is that on invalid form submission (HTTP 422), I can't load the new response in the page so I lose the validation errors. (is there a way to?)
Best case scenario I would not listen to a form submit and I would instead somehow listen for progress on the form submission itself.
Based on my research, it's not yet possible to listen for progress with Fetch
It's planned: https://chromestatus.com/feature/5274139738767360
Is there any workaround?
The text was updated successfully, but these errors were encountered: