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

Protractor Timeouts #76

Closed
coryrylan opened this issue Dec 6, 2016 · 7 comments
Closed

Protractor Timeouts #76

coryrylan opened this issue Dec 6, 2016 · 7 comments

Comments

@coryrylan
Copy link

coryrylan commented Dec 6, 2016

When running protractor test they will timeout on any component using the lazy load directive. Protractor watches the ngZone to know when pending xhr calls, timeouts and intervals are completed before running.
In the scroll-listener.ts the .sampleTime(100, scheduler) creates a interval that wont ever end during a protractor test. I found a way arount this by the adding the following code to the directive

ngAfterContentInit() {
    this.ngZone.runOutsideAngular(() => { // run outside angular
      this.scrollSubscription = getScrollListener(this._scrollTarget)
        .filter(() => this.isVisible())
        .take(1)
        .switchMap(() => this.loadImage(this.lazyImage))
        .do(() => this.setImage(this.lazyImage))
        .finally(() => this.setLoadedStyle())
        .subscribe(() => this.ngOnDestroy(),
        error => {
          this.setImage(this.errorImg || this.defaultImg);
          this.ngOnDestroy();
        });
    });
  }

According to this https://github.com/angular/protractor/issues/3349#issuecomment-232253059 Protractor watches the main ngZone so if we run the interval out of it protractor run successfully. I'm not sure how this would work with the protractor tests on this project but I can try to make a pull request when I get the chance.

@tjoskar
Copy link
Owner

tjoskar commented Dec 12, 2016

Thanks for your feedback.
I can however not reproduce this. I'm using protractor in this project and it seams to work fine. But having said that, it may be a good idea to use ngZone.runOutsideAngular for performance improvement. But if we are using ngZone.runOutsideAngular, we need to use ChangeDetectorRef after we have lazy loaded the image, right? So angular knows that the view needs to rerender.

@tjoskar
Copy link
Owner

tjoskar commented Dec 12, 2016

Since I can not reproduce this and it seams that you have a working solution. Do you want to submit a PR?

@coryrylan
Copy link
Author

Sure, I'll see if I can get one in within the next week :)

tjoskar pushed a commit that referenced this issue Dec 29, 2016
@tjoskar
Copy link
Owner

tjoskar commented Dec 29, 2016

I created a new version of the plugin. Can you try it out: npm install ng2-lazyload-image@2.2.3-0 to see if it fix the problem?

@coryrylan
Copy link
Author

Sure! I'll try it out today

@tjoskar
Copy link
Owner

tjoskar commented Jan 22, 2017

Closing this. Let me know if you still get timeouts.

@tjoskar tjoskar closed this as completed Jan 22, 2017
@coryrylan
Copy link
Author

@tjoskar just tested this today and it works, thank you for the fix! :)

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

No branches or pull requests

2 participants