Navigation Menu

Skip to content
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

Updating v1.0.2 to v.1.2.3 - Some Ajax calls not completing #509

Closed
euangordon opened this issue Nov 23, 2020 · 15 comments · Fixed by #514 or #518
Closed

Updating v1.0.2 to v.1.2.3 - Some Ajax calls not completing #509

euangordon opened this issue Nov 23, 2020 · 15 comments · Fixed by #514 or #518

Comments

@euangordon
Copy link

euangordon commented Nov 23, 2020

Hi,

I have been using v1.0.2 for some time, but started noticing issues with Firefox keeping Pace.js running even after the page has loaded. I know this has been recorded and should be fixed in v1.2.3.

After upgrading to v1.2.3, I now see that some of my AJAX get calls are not working properly. The API gets hit and returns data, but I never get into the Ajax success or error. I can get it to fail consistently for some calls, but others to the same API work fine. So I wonder if it is larger datasets that are causing the issue?

Rolling back to v1.0.2 and my AJAX calls are back working but the FF issue persists.

My paceOptions:

paceOptions = { ajax: { trackMethods: ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'], ignoreURLs: ['mouseflow', 'mainHub', '__browserLink', 'browserLinkSignalR', 'ServiceBusTopicHub', 'signalr'], trackWebSockets: false } }

In the below code, it sometimes never enters the success or error when using v1.2.3, but always works using v1.0.2

$.ajax({
        url: getAbsoluteUrl(' / ') + "api/AdminSections?vesselid=" + Vessel.ID,
        type: 'GET',
        dataType: 'json',
        success: function (folios) {
            console.log("Success");
            console.log(folios);
        },
        error: function (request, message, error) {
            console.error(message);
            handleException(request, message, error);
        }
    });
@euangordon euangordon changed the title Updating v1.0.2 to v.1.2.3 - Some Ajax calls now completing Updating v1.0.2 to v.1.2.3 - Some Ajax calls not completing Nov 23, 2020
@mugnap
Copy link

mugnap commented Dec 14, 2020

Yes, this happens to me too.

@euangordon
Copy link
Author

@mugnap Do you have any idea what causes it, any work around found? I will make a jsfiddle now

@mugnap
Copy link

mugnap commented Dec 16, 2020 via email

@Arimov
Copy link

Arimov commented Dec 17, 2020

I confirm. I have the same problem. This code does not transfer control to saccess section:

 $.ajax({
                url: actionurl,
                type: 'post',
                dataType: 'json',
                data: $("#loginForm").serialize(),
                success: function (data) {
                    window.location.href = data.destinationUrl;
                },
                error: function (data) {
                    let errorMessage = "Error logging in";
                    try {
                        errorMessage = JSON.parse(data.responseJSON.error).error_description;
                    } catch{

                    }
                    errorToast(errorMessage, "Error logging in");
                }
            });

After returning to version 1.0.2 - everything works fine

@clementmoulin
Copy link

Having the same issue here. Really complicated to debug, since this does not happen each time (for the same event sometimes the success() callback is called, sometimes not...).

Revert to 1.0.2 : fine again !

@euangordon
Copy link
Author

Having the same issue here. Really complicated to debug, since this does not happen each time (for the same event sometimes the success() callback is called, sometimes not...).

Revert to 1.0.2 : fine again !

I can get it to happen everytime, but I couldn't get a jsfiddle to connect to my API due to CORS :(

@hbtsmith
Copy link

I have the very same problem

@CodeByZach
Copy link
Owner

Having the same issue here. Really complicated to debug, since this does not happen each time (for the same event sometimes the success() callback is called, sometimes not...).
Revert to 1.0.2 : fine again !

I can get it to happen everytime, but I couldn't get a jsfiddle to connect to my API due to CORS :(

Hi @euangordon,

Could you please elaborate on this? Would very much like to work on getting this resolved.

Thank you!

@PierreAronnax
Copy link
Contributor

PierreAronnax commented Feb 15, 2021

jQuery uses:

// Listen to events
xhr.onload = callback();

Which is completely overwritten by Pace:

	addEventListener = function(obj, event, callback) {
		return (typeof obj.addEventListener === "function" ? obj.addEventListener(event, callback, false) : void 0) || (obj["on" + event] = callback);
	};
...
	XHRRequestTracker = (function() {
...
				_ref2 = ['load', 'abort', 'timeout', 'error'];
				for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
					event = _ref2[_j];
					addEventListener(request, event, function() {
						completeCallback(_this);
						return _this.progress = 100;
					}, false);
...
	})();

I have rewritten addEventListener to use Events when obj.addEventListener isn't available:
The original event (when available) is first added to the list, and then one or more callbacks are added.

	addEventListener = function(obj, event, callback) {
		return (typeof obj.addEventListener === "function") ? obj.addEventListener(event, callback, false) : function() {
			if (typeof obj["on" + event] !== "function" || typeof obj["on" + event].eventListeners !== "object") {
				var eventListeners = new Events();
				if (typeof obj["on" + event] === "function") {
					eventListeners.on(event, obj["on" + event]);
				}
				obj["on" + event] = function(evt) {
					return eventListeners.trigger(event, evt);
				};
				obj["on" + event].eventListeners = eventListeners;
			} else {
				var eventListeners = obj["on" + event].eventListeners;
			}
			eventListeners.on(event, callback);
		}();
	};

I can create a pull-request if you want.

@CodeByZach
Copy link
Owner

Please do.

@PierreAronnax
Copy link
Contributor

A few observations:

  • obj.addEventListener returns undefined, therefore obj["on" + event] was overwritten also when obj.addEventListener is a function
    I'm not sure what the original intention was. It works just fine if I only call obj.addEventListener. I am not sure if my whole code is needed anymore.
  • obj can be reused: obj.addEventListener is called multiple times on the same object and adding the same callback again
    This is not good and must be fixed. removeEventListener can't be used because callback is an anonymous function.
  • obj can be reused, that's why I haven't created one obj.eventListeners to be shared between different events to avoid above problem

@PierreAronnax
Copy link
Contributor

  I'm not sure what the original intention was. It works just fine if I only call obj.addEventListener. I am not sure if my whole code is needed anymore.

Found it: #230

PierreAronnax pushed a commit to PierreAronnax/pace that referenced this issue Feb 17, 2021
obj["on" + event] was overwritten also when addEventListener was available.
Now adding an event fallback when addEventListener is unavailable.
The original event (when available) is first added to the list, and then one or more callbacks are added.

Fixes CodeByZach#509

Signed-off-by: Luuk Bosma <l.bosma@interay.com>
@CodeByZach CodeByZach linked a pull request Mar 3, 2021 that will close this issue
@euangordon
Copy link
Author

Hi All,
Tried v1.2.4 and it seems to work just fine.
Many thanks to @PierreAronnax

@fcorbeil
Copy link

fcorbeil commented Mar 3, 2021

Problem solved on my side too, thanks!

@Arimov
Copy link

Arimov commented Mar 11, 2021

Thanks for the good job. The new version (1.2.4) works fine for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants