Skip to content

ngUpgrade: $digest already in progress  #8004

Closed

Description

@christopherthielen

In an ng-upgrade application, a $digest already in progress error is thrown in some specific case.

Steps to reproduce and a minimal demo of the problem

From within a downgraded ng2 component:

  • Inject ng1 services: $http and $location
  • Fetch some data using $http
  • Chain a .then off the $http.get() which updates the url using $location.url('/foo')

http://plnkr.co/edit/KBcwSi?p=preview

What steps should we try in your demo to see the problem?
Click Button #3 of the NG2 component

Current behavior
HTTP data is fetched, logged to console, and the url updates to '/foo'. The $digest already in progress error appears in the console.

Expected/desired behavior
HTTP data is fetched, logged to console, and the url updates to '/foo'. No $digest errors should appear in console

Other information

These steps to reproduce were distilled down from UI-Router's hybrid ng1/ng2 sample app.

  • This happens against Angular 2 beta 14
  • If you only fetch HTTP without location, or only update the location without chaining off a $http the error does not occur
  • If you chain off a $timeout instead of a $http.get() the error does not occur
  • If you initiate the promise chain from within the ng1 context (instead of inside the ng2 component), the error does not occur.

@ericmartinezr helped me replace angular2-polyfills with core.js and zone 0.6.10 and the issue still occurs. Here is that plunk: http://plnkr.co/edit/Hxt062?p=preview

Possibly related? #7666

Activity

  1. thesnabe commented on Apr 19, 2016

    @thesnabe

    I am having this issue aswel. I don't notice any side effects from it though.

  2. adamduren commented on Apr 22, 2016

    @adamduren

    I have this issue as well when using $state.go from ui-router. Unfortunately the only thing I could find to fix it was to upgrade the Controller to a Component.

  3. thelgevold commented on May 18, 2016

    @thelgevold
    Contributor

    I am seeing $digest issues as well when bootstrapping an A1 application using ngUpgrade. My code is using RC 1.0

     ng1compilePromise = new Promise((resolve, reject) => {
          ng1Module.run([
            '$injector',
            '$rootScope',
            (injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => {
              ng1Injector = injector;
              ngZone.onMicrotaskEmpty.subscribe(
                  {next: (_) => ngZone.runOutsideAngular(() => rootScope.$apply())});
              UpgradeNg1ComponentAdapterBuilder.resolve(this.downgradedComponents, injector)
                  .then(resolve, reject);
            }
          ]);
        });
    

    I've included the code block from upgrade_adapter.ts where it happens.

    Isn't it considered a bad practice to call $apply() directly. I realize this is a bit different, but I have generally stayed away from direct calls like this, and instead wrapped my code in a $timeout or similar.

    I tried this a while back in Beta 1 and it was working.

  4. thelgevold commented on May 31, 2016

    @thelgevold
    Contributor

    My issue seems to be related to a $state.go in ui-router as well. Not seeing the error if I navigate directly to the final url and bypassing the $state.go step.

  5. andreialecu commented on Jun 7, 2016

    @andreialecu
    Contributor

    I'm having the same issue and it is completely killing performance for my app after the error occurs.

    However, changing the rootScope.$apply() to a simple $timeout(() => {}); call seems to fix this, and is also the recommended workaround as per http://stackoverflow.com/questions/12729122/angularjs-prevent-error-digest-already-in-progress-when-calling-scope-apply

    I'm going to submit a PR for this.

  6. thelgevold commented on Jun 7, 2016

    @thelgevold
    Contributor

    I already submitted a PR

  7. thelgevold commented on Jun 7, 2016

    @thelgevold
    Contributor

    It's pending review

  8. andreialecu commented on Jun 7, 2016

    @andreialecu
    Contributor

    @thelgevold great! didn't see it.

  9. andreialecu commented on Jun 7, 2016

    @andreialecu
    Contributor

    @thelgevold I already had a PR submitted and accepted for that particular line of code as well.

    Quite a buggy line looks like. 😄

  10. mhevery commented on Jun 8, 2016

    @mhevery
    Contributor

    fixed by #6386

  11. christopherthielen commented on Jun 8, 2016

    @christopherthielen
    Author
  12. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  13. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions