Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Strange issue with fastclick and angularJS in cordova/phonegap in iOS with the bind function #466

Open
pauloya opened this issue Apr 13, 2016 · 6 comments

Comments

@pauloya
Copy link

pauloya commented Apr 13, 2016

Hi,
We were getting errors with a callstack that looked like this:

  1. 2016-04-13 15:05:50,911 ERROR - Error: [$rootScope:inprog] $digest already in progress
    http://errors.angularjs.org/1.5.0/$rootScope/inprog?p0=%24digest
    https://aaa.com/web/common/frameworks/angular.js:68:32
    beginPhase@https://aaa.com/web/common/frameworks/angular.js:17178:31
    $apply@https://aaa.com/web/common/frameworks/angular.js:16918:21
    https://aaa.com/web/common/frameworks/angular.js:24551:29
    dispatch@https://aaa.com/web/scripts/frameworks/jquery-2.1.1.min.js:3:6409
    handle@https://aaa.com/web/scripts/frameworks/jquery-2.1.1.min.js:3:3184
    dispatchEvent@[native code]
    sendClick@https://aaa.com/web/scripts/frameworks/fastclick.js:295:30
    **onTouchEnd@https://aaa.com/web/scripts/frameworks/fastclick.js**:589:18
    https://aaa.com/web/scripts/frameworks/fastclick.js:105:43
    send@[native code]
    send@https://aaa.com/web/scripts/frameworks/jquery-2.1.1.min.js:4:14959
    ajax@https://aaa.com/web/scripts/frameworks/jquery-2.1.1.min.js:4:10583
    ajax@https://aaa.com/fins.api/Scripts/jquery.signalR-2.2.0.min.js:8:16074
    ajaxSend@https://aaa.com/fins.api/Scripts/jquery.signalR-2.2.0.min.js:8:18424
    send@https://aaa.com/fins.api/Scripts/jquery.signalR-2.2.0.min.js:8:26147
    send@https://aaa.com/fins.api/Scripts/jquery.signalR-2.2.0.min.js:8:11696
    invoke@https://aaa.com/fins.api/Scripts/jquery.signalR-2.2.0.min.js:8:34506
    subscribeModel@https://aaa.com/fins.api/signalr/hubs:105:62
    subscribeModelWithPromise@https://aaa.com/web/common/services/ModelCacheService.js:99:58
    https://aaa.com/web/common/services/ModelCacheService.js:40:52
    each@https://aaa.com/web/scripts/frameworks/jquery-2.1.1.min.js:2:2938
    https://aaa.com/web/common/services/ModelCacheService.js:39:23
    $emit@https://aaa.com/web/common/frameworks/angular.js:17070:38
    https://aaa.com/web/common/services/SignalRService.js:214:43
    processQueue@https://aaa.com/web/common/frameworks/angular.js:15552:30
    https://aaa.com/web/common/frameworks/angular.js:15568:39
    $eval@https://aaa.com/web/common/frameworks/angular.js:16820:28
    $digest@https://aaa.com/web/common/frameworks/angular.js:16636:36
    $apply@https://aaa.com/web/common/frameworks/angular.js:16928:31
    https://aaa.com/web/common/frameworks/angular.js:18753:42
    completeOutstandingRequest@https://aaa.com/web/common/frameworks/angular.js:5804:15
    https://aaa.com/web/common/frameworks/angular.js:6081:33

The strange thing here is that ajax native send seems to call the onTouchEnd function.
We could replicate the problem by touching the screen while an ajax call was pending (I'm not completely sure of the internals, but we could always replicate by touching the screen at a point where ajax would run).

This didn't happen in the browser, happened only within the cordova app in iOS.

We were able to fix it by renaming the function bind to fcBind. I believe this code somehow hooked event handlers with events it wasn't supposed to.

for (var i = 0, l = methods.length; i < l; i++) {
    context[methods[i]] = bind(context[methods[i]], context);
}

Like I said, renaming the function bind() to fcBind() fixed it.
I thought I would leave this here in case someone else has a similar issue.

@TombolaShepless
Copy link

@pauloya We're seeing the same issue. Thanks for posting this, will try the fix!

@TombolaShepless
Copy link

@pauloya We took a slightly different approach if you're interested:

FastClick.prototype.sendClick = function (targetElement, event) {
     window.setTimeout(originalFunction.bind(this, targetElement, event));
}

@pauloya
Copy link
Author

pauloya commented Apr 25, 2016

Hi,
I don't think our fix is relevant, because we minify and the function is renamed anyway, and we still get errors.
We did a similar fix on our side, making it asynchronous.

I'm still confused as to why an ajax send would trigger fastclick. Sounds like doing the async call doesn't solve the real problem, but just the symptom.

There is a similar issue reported here:
https://stackoverflow.com/questions/29992980/debugging-digest-already-in-progress-error/36839750#36839750

@briananderson1222
Copy link

briananderson1222 commented Sep 9, 2016

Any word on whether the above fix might find its way into the source?

@briananderson1222
Copy link

anyone mind sharing more details around how this problem was "fixed" did you just overwrite the implementation of sendClick to wrap the dispatchEvent in a setTimeout function?

@michaelabuckley
Copy link

I've published a PR at #533.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants