-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[Search] - Ajax abort not correct "there was an issue querying the server." #2779
Comments
The problem is easier to reproduce with a remote data source, it doesn't even really need to be typed that quickly. I've got a search component hooked up to a remote API and this error shows up pretty much any time you make a spelling mistake. |
Abort is on purpose, this prevents an edge case where a previous request takes longer to load than the last request. So for example: With abort:
Without abort
|
@jlukic the abort is correct, but the semantic-ui code has a bug. i have explained in detail the bug and the solution. the problem is that there are 2 ajax requests which are isolated and correct. but the semantic ui status code is a singleton and mixes the 2 requests which is wrong and the bug. the status must be attached to the request and not the query object. if the ...fail() function is handled correctly, then the first ajax request is aborted. then the second ajax requests finishes and the result will be shown correctly. the problem is "API Request failed... status abort" is copied from request 1 to request 2 which is a bug. the API request of the second ajax request should be something like ok. its clearly a bug which can be reproduced. i use the semantic-ui code in a project and i had to fix this fail() function so that remote request are handled correctly. otherwise i get this "server error" which is no server error, but a bug in handling the abort or more precicely handling the status code inside the semantic-ui api which does not separate the requests correctly but stores a global variable for the query function which is wrong. it works most of the time, but if ajax.abort is happening then its wrong and a bug which must be fixed. |
@jlukic "5) "S" the stubborn query that hit just too many DB rows, finally loads and replaces the results with "S" results (showing incorrect search results)." this never happens, because the abort handles this correctly.by typing "Sea" the "S"-Request is aborted and stops the loading of the result of this request and the result thrown away. the loading of this request is stopped and it does not matter what the server returns. abort must be used, there is no question about it. but the semantic-ui api code must handle the ...fail() correctly. |
The labels on the above steps were swapped by accident. "With abort" should have been "without abort" and vice versa, i've gone ahead and edited the above message. I'm not sure I've experienced the Can you outline a specific set of steps to reproduce the issue? |
i cannot see swap in your comment. again, the abort() which is triggered by the xhr ajax request is a good thing, because if you go ahead and change "S" to "Sea" then the request with "S" needs to abort, as its not valid anymore. you are now only interested in the result of "Sea". somehow the abort() call ends up in the semantic-ui api and sets the "Api Reqeust failed: ... statusText = "abort" " which is the behavior that we want. but in the semantic.js code is a bug which causes the second request with "Sea" to break, because the request with "S" set the status of the API to "abort" by changing a global variable, which is read by the second request. but it should be status "ok" as the status of request2 is ok. this then leads to a chain-reaction and all following requests are then aborted, even if they are loading correctly. i repeat myself. two (or more) objects write to the same api variable and overwrite each in a incorrect way. in the screenshot i have expanded the "v API" in the console, all the values are coming from the last request, but only the line "API error" comes from a global variable, the output in the console then is a mixed object, but it should only contain data from the request. this means the status error needs to be moved from the global API.query.errors to API.query.request1.errors , API.query.request2.errors etc. so that the error of one request dont interfere with the results of other requests. the code here is quite complicated with many callbacks so i try to explain the main problem here in a simplified way. i might try to create a demo-page with a fix or workaround to compare the broken and the fixed behavior. there is a real bug here and it can be fixed. thats why i posted this issue. its easily reproducible, even if its a corner-case, but many users will hit this bug, as the nature of a suggest is, that you interact with the results by typing while its loading which means you cause a lot of xhr.aborts which is ok, but must be handeld correctly by the semantic ui API. here the api is simply a function which takes care of the query-function which then handles the xhr request. the main problem is the usage of a global variable where one would need one variable per request then the bug would be fixed. if you modify the code in $api.search.query.event.fail: function(){ return false;} then the error-status is not set and the suggest behaves like you want. the bug is now 20+ days open and nobody wants to fix it, because they don't understand the problem and the mistakes in the semantic.js code. also the bug is a bit tricky to reproduce, so i might try to write some code you can put into console to trigger the error like
expected result: popup shows response from "Sea" query |
@ayurmedia did you work out a temporary fix for it? I'm definitely experiencing the same issue as you. |
I'm also having the same issue. You can even test on the documentation. Usually happen when a previous request gets aborted. |
@dontfeedthecode yes i have a fix/workaround. i will fork the github project and add a fix and make a pull request. the solution is to test if the error-type is abort and then return false in the ...fail() function. because we can simply ignore the abort at some point as it simply does not show results, which is actually the behavior we want. then the following ajax request will work correctly and show results because the API-status is not broken by the false handling of abort. didn't see side-effects yet. my first try was to simply ...function fail() { return; } which works, but it will ignore real server errors, but we want to display if the server had some real error like timeout , 503 or malformed json-response . important while developing to get feedback when your json is wrong and not just ignore the warning like abort. actually abort is not an error, abort is a user-interaction and a feature. |
@jlukic i might host a api response server on my private website, which will simply echo the search-string and return a valid json response. additionally with a delay of 1second or more so one can test the abort case in a relaxed way. because to reproduce the bug you need to abort before the server returns a 200 response, otherwise its not an abort. so if the server waits with the response for a while its easier to produce abort. i probably found the bug because my server-search response was slow, so i hit the abort quite often. if the server is very quick then it often returns a valid json with status 200 and no abort. but the semantic-ui server is broken as it often returns "false gateway" which makes it hard to test features. is it possible to host dynamic code on github like node.js or php ? |
I have created a sandbox to test the bug, there is also one with a solution: you can also use this echo-server to play with your own implementation. The test-form has 3 cases to test the bug easily, open developer console and network/xhr to see what happens or console. Here is an example form with the currently (master branch) broken 2.0.8 version of semantic.js Here is a form with the patched version i also have a patched version on a cloned git-hub project here: https://github.com/ayurmedia/Semantic-UI/blob/master/dist/semantic.js or The workaround is at line 18370 in current (2.0.8) dist/semantic.js in github (just commenting out the line) if(timeLeft > 0) {
module.debug('Response completed early delaying state change by', timeLeft);
}
setTimeout(function() {
if( module.is.abortedRequest(xhr) ) {
//module.request.rejectWith(context, [xhr, 'aborted', httpMessage]);
}
else {
module.request.rejectWith(context, [xhr, 'error', status, httpMessage]);
}
}, timeLeft);
}
}, this workaround does not change the fail() function, but uses the existing test on "module.is.abortedRequest" which should be more correct with less side-effects. aborted is not a real error, so rejectWith() is not the correct way to do it. if its a real error then still the error-message will be shown. (in the else case) edit: improved markdown for better syntaxhighlight |
@ayurmedia Awesome work mate, very impressed. That fix works like a charm! |
I'll review this when i return to development next week. |
any updates on this? I'm experiencing the same problem |
I am also having this issue and had to switch to JQuery ui autocomplete for now. I really love semantic ui, but there are a few core components that still don't work as expected. Keep up the good work! |
seriously what's going on with this bug, it's now open for month and still in evaluating phase, even its confimed as a serious bug several times. this reduces credibility of the semantic-ui team a lot. there is a workaround and solution for the bug. this is really lazy. the autocomplete, search is an essential gui widget and should work, or people use other frameworks if semantic-ui does not work. Assignee: why ? nobody responsible for the bug ? |
I am sure everyone is working very hard, relax, try some earl grey. |
FYI I'm seeing this as well! Getting on the chain for updates! |
Hi there, just FYI, I see the same bug in my project. @ayurmedia's fix works, but I understand it's not the ideal. |
Hey @ayurmedia i need your help on this... http://stackoverflow.com/questions/33719852/sementic-ui-search-module-with-api-issue Thanks |
@revosys , seems your stackoverflow question has nothing to do with the bug, and you just need to read the manual to use semantic-ui search in the normal way. if you make a jsfiddle using my sandbox demo as a base for example, i might be able to help. the code snippets on stackoverflow don't help me understand your problem. here we discuss about the bug, that the abort-method is implemented wrong and should be fixed by the developers of semantic ui, still not fixed after 3 month. |
hey @ayurmedia what i want to know that how replace the URL with localhost "sub/data.json?q={query}" so that it search in "title" of my json file... and if result found than it show the result here is my json file... My issue is when i use the above code, and search something it show all result from json file without searching the typed words... Thanx |
@jlukic typing itself can abort previous ajax calls. Here's a self contained node/express script to reproduce the issue easily: https://gist.github.com/anonymous/ee5cfbbe436b860c8ecf (Edit: new gist which disabled cache) I don't know if there's way to discern xhr requests aborted by continuing to type, but perhaps a solution would be to only fire onAbort when the aborted xhr request is the most recent xhr request. |
@ayurmedia FYI, you can join the Gitter chat in the future to have off-topic discussion |
@woodlandhunter did you check my test-case i discribe in the post from aug 26. it makes the error reproducible 100% of the time because the crucial ajax is slowed down. the bug is only visible if there is a new xhr when the last xhr did not finish yet. (eg. you have 2 xhr in parallel). most developers use fast server and dont understand the bug. i have a complex autosuggest on the serverside so i cached the bug quickly and then improved my backend to give faster responsetimes also. there is no doubt the bug is real. one dirty way could be to make the xhr more sync, eg. if a second xhr is opended then kill all old xhrs so the abort cannot kill the newest xhr. because the newest xhr is the best one for the time. |
i reported the bug at v 2.0.8 , now in 2.1.8 its still not fixed. |
the idea of tracking all active xhr requests and kill them instantly if a new one starts sounds good 👍 |
@ayurmedia I don't think anyone disagrees that there is a bug. You can see from the gist I provided that I understand the bug. @jlukic I can confirm part of what is stated in the original report and outline the steps that happen:
Storing the current value of There's a similar use of the I hope I was clear enough in my explanation. |
@woodlandhunter the bug is still in status "evaluation" so its not 100% confirmed the bug is real. your observation of the timeouts and rejectWith is correct as i can see. as its connected to module and not the xhr event seems to be the problem. the workaround like @larsbo +1 is to remove old xhr requests when the new xhr request is opened, to prevent a late call on onAbort which will then interfere with the new xhr. if a new xhr is started in the module (other xhrs could run from other modules at the same time) then old xhrs should be stopped immediately so that the late abort from the first xhr cannot influence the latest xhr. the bug only appears if there are 2 xhrs running at the same time. a) user types by ignoring the onAbort xhr2 can display the correct (but late) response. and is not broken by xhr1 |
I am able to consistently reproduce the issue with network throttling. Will have something soon. |
…. Causing Callbacks to be set on LAST request on new request
@ayurmedia @woodlandhunter @larsbo I've made two changes to fix this. The first, in API, The second half of the issue was that This would cause the settings for the running instance to be modified to new I've fixed the issue by making sure full API |
@ALL Thanks for working on this! |
I've also verified using APISettings with dropdown should be fine. |
The example supplied by @ayurmedia works but it's very hard to find the diff to generate a patch, also his example is using a very old version of semantic.js (2.0.8). I'm still having this bug, and I am using the 2.1.8 version, someone already released a pull request ? Or there is a patch for this ? |
@brunofunny the bug is fixed already, you need version 2.1.9 or 2.2 , or the version here from github. 2.1.8 is the last version with the bug. |
Which branch is being used @ayurmedia ? I"ve tried the "master" and it's (at least in the comment) at 2.1.7 version, and I cannot find the 2.1.9 nor 2.2 version to download anywhere. Do you have the link for it ? |
Just for the notes, the release 2.2 is being maintained at the branch "next", there was the only place I found it. The version 2.1.9 I couldn't find at all. |
Steps to Reproduce
Expected
The Search should do this:
Result
The Search does not do this:
Bug is somewhere module.request.rejectWith, which will break ajax requests after this
$api.search.query.event.fail...
if one returns in fail() then search works like expected.
Testcase
the bug can be reproduced on the semantic-ui page:
http://semantic-ui.com/modules/search.html
when you quickly type different words in the searchbox you can produce "abort". (unfortunately semantic-ui-com often responds with 502 Bad Gateway, but it should be abort.
the GET is Aborted, and another GET is successful.
the API Debug now should trigger the display of the results, but because of global vars or a race-condition the second Ajax request also shows API => "API request failed" which is the cause of the Bug.
the error-message of the first GET gets copied over to the second GET (ajax) request and then shows the server-error, which is wrong, because the second request was successful.
if the callback of $api.search.query.event.fail: function()... returns early then the result-list will be shown.
to turn on debug log in js-console on semantic-ui website enter following in the javascript-console.
$('.ui.search').search({'debug':1,'verbose':1,'cache':0});
The text was updated successfully, but these errors were encountered: