-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Changing XHR to Fetch API #1845
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work. I appreciate the modernisation. For this core functionality, we should take extra care to maintain compatibility and not introduce any bugs. Please see my comments.
onError = (type, error, options) -> | ||
options.error?.call options.context, type, error, options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some usages for the error handler and progress callback:
devdocs/assets/javascripts/app/db.coffee
Lines 253 to 257 in 676f4f6
ajax url: entry.fileUrl() dataType: 'html' success: onSuccess error: onError devdocs/assets/javascripts/app/update_checker.coffee
Lines 14 to 17 in 14049da
ajax url: $('script[src*="application"]').getAttribute('src') dataType: 'application/javascript' error: (_, xhr) => @onUpdateReady() if xhr.status is 404 devdocs/assets/javascripts/models/doc.coffee
Lines 67 to 70 in 14049da
ajax url: @indexUrl() success: callback error: onError devdocs/assets/javascripts/models/doc.coffee
Lines 114 to 119 in 14049da
ajax url: @dbUrl() success: success error: error progress: onProgress timeout: 3600
abort = (xhr) -> | ||
clearTimeout(xhr.timer) | ||
xhr.onreadystatechange = null | ||
xhr.abort() | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's one usage of abort:
devdocs/assets/javascripts/views/content/entry_page.coffee
Lines 112 to 114 in 93a42cc
if @xhr @xhr.abort() @xhr = @entry = null
if options.dataType == 'json' | ||
response.json() | ||
else | ||
response.text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think response.ok
and response.status
(200 <= xhr.status < 300
) need to be checked.
hey @simon04 we were reviewing your comments and the code, and we have some concerns if this move from xhr to fetch is actually beneficial or not. I can describe a bit of what we found:
Also, we noticed one thing that seems to be a bug in the current code, this error callback
xhr as the second argument, but that's actually passed as the third argument here
We want to raise these concerns before continuing with this change, we are not sure if it's really worth it (the current code works just fine and some of the code around it was designed for how xhr works) |
@arielj, @toppa and I are submitting this PR for this issue: #1193
We had a few differences between XHR and Fetch, so we couldn't match functionality 100%.
But we think it's fine from what we saw on the code.
onProgress
callback or equivalentWe couldn't find usages of the
xhr
argument on callback methods. We weren't sure about the arguments.