I was having the same issue with an infinite scroll and a masonry of images and finally was able to "force" chrome to stop debouncing the request for more images by simulating clicks on the document. I know it sounds weird but when I was testing, as long as I was scrolling, the request would infinitely debounce but as soon as I clicked once, it would instantly execute the XHR.
Here's how I did it...:
export function getPosts() {
return (dispatch: Dispatch<any>, getState) => {
const { postFeedState }: IGlobalState = getState();
dispatch(handlePostsCancellation())
dispatch({ type: postFeedTypes.GET_POSTS_REQUEST });
const feedFilterDto = getFeedFilterDto(getState);
// this is where the clicks are simulated
setTimeout(() => {
for (let i = 0; i < 3; i++) {
const evt = document.createEvent("Events");
evt.initEvent("click", true, true);
window.dispatchEvent(evt);
}
}, 50);
return dispatch(setCancelSource(postFeedTypes.SET_MAIN_FEED_POSTS_CANCEL_SOURCE))
.then((source) => PostController.getMainFeedPosts(postFeedState.get("postsToSkip"), FeedDisplay.THREE_COLUMNS, feedFilterDto, source))
.then(posts => dispatch(getPostsSuccess(posts)))
.catch(error => {
if (axios.isCancel(error)) return;
dispatch({ type: postFeedTypes.GET_POSTS_FAILURE });
dispatch(handleApiError(error, null));
});
}
}
I first tried with only one click and it worked almost all the time and then tried 2-3 clicks and worked all the time. To be honest I still feel a little weird about that timeout/click code but what ever works, works! Also, time will tell if this will keep on working but for now this is best solution and easiest solution I've found yet.
P.S: I use redux and axios and have my own custom classes for my endpoints (PostController) but all it does is an axios(XHR) request.