Hi,
I’m encountering an issue while using the Atlassian AP library to fetch data. Specifically, when I start or delete a query, I’m receiving duplicate results. I’ve tried implementing debounce and delay mechanisms, but the problem persists.
Problem:
-
When I type in the search input or click the delete button, I receive duplicate results from the API.
-
I suspect that multiple simultaneous requests are being made, but I’m not sure how to properly handle or prevent this.
AP.request({
url: url,
type: "GET",
data: reqParams,
success: (responseText) => {
var response = JSON.parse(responseText);
let values = [];
if (response) {
values = response.values.map(({ id, name }) => ({ value: id, displayName: name }));
if (fieldValue !== "") {
values = values.filter((v) => v.displayName.toLowerCase().startsWith(fieldValue.toLowerCase()));
}
values.sort((a, b) => a.displayName - b.displayName);
}
onSuccess(values);
},
error: function (xhr, statusText, errorThrown) {
console.log(errorThrown);
}
});
How can I ensure that only one API request is made at a time, and prevent duplicate results when the query changes or is deleted?