You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have detected some unusual behavior when overriding the transport property of the remote option.
Basically, I do some logic before determining if the response should be made, like so:
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'mysite.com?searchPlugins&q=%QUERY',
wildcard: '%QUERY',
cache: true,
transport: function (options, onSuccess, onError) {
var query = input.val(); // get the query
if(query.startsWith('something')) {
// make the request
// abort previous requests made by typeahead
options.url = options.url.replace('something', ''); // remove "something" from query
$.ajax(options)
.done(function(data, textStatus, request) { onSuccess(data); })
.fail(function(request, textStatus, errorThrown) { onError(errorThrown); });
}
}
}
});
However, if the if(query.startsWith('something')) { does not fire, resulting in neither onSuccess or onError are being called, then it might break the request from every being sent again. It only happen after X amount of requests sent, so the next request might work, but then after that, they will never fire.
I have debugged this issue, somewhat successfully, by removing the if(query.startsWith('something')) { statement. In this case, requests will always be sent, despite it being against the usecase.
I only want the request to be sent if the query contains something, otherwise not.
I am not sure if anything in the codebase depends on onSuccess or onErroralways being called?
The text was updated successfully, but these errors were encountered:
My workaround, that fixes the issue, is below code.
If the query string is not present, the request is aborted just after being executed. That results in onError being executed. I have noticed onError will execute the function cb(true).
It's not pretty, but it at least doesn't prevent future remote responses from being fired, and it prevents unnecessary overhead for the server, processing requests, it shouldn't have received in the first place.
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: 'mysite.com?searchPlugins&q=%QUERY',
wildcard: '%QUERY',
cache: true,
transport: function (options, onSuccess, onError) {
var query = input.val(); // get the query
// make the request
// abort previous requests made by typeahead
options.url = options.url.replace('something', ''); // remove "something" from query
var request = $.ajax(options)
.done(function(data, textStatus, request) { onSuccess(data); })
.fail(function(request, textStatus, errorThrown) { onError(errorThrown); });
if(!query.startsWith('something')) {
request.abort();
}
}
}
});
I have detected some unusual behavior when overriding the
transport
property of the remote option.Basically, I do some logic before determining if the response should be made, like so:
However, if the
if(query.startsWith('something')) {
does not fire, resulting in neitheronSuccess
oronError
are being called, then it might break the request from every being sent again. It only happen after X amount of requests sent, so the next request might work, but then after that, they will never fire.I have debugged this issue, somewhat successfully, by removing the
if(query.startsWith('something')) {
statement. In this case, requests will always be sent, despite it being against the usecase.I only want the request to be sent if the query contains
something
, otherwise not.I am not sure if anything in the codebase depends on
onSuccess
oronError
always being called?The text was updated successfully, but these errors were encountered: