-
Notifications
You must be signed in to change notification settings - Fork 142
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
Images are not loaded after switching between routes #438
Comments
Hi @zZeepo, thanks for sharing your issue. First of all I have some questions:
Regarding your issue, you are probably right regarding that the content might not be removed before the |
Hey @tjoskar,
After trying around for a bit now, I think I will give the Regarding the issue: |
Interesting! Thanks for sharing, I really appreciate it! I just tried to change to the Just so you know, in version |
Now when I'm thinking about it, I think it can be hard to know the state of every event (know if the dom has been updated or not when we got the first event). |
hmm... I installed your example application and the error actually does not show up there for me as well. I'm now trying to find the difference between your and my application. The routing seems to behave different: I'll do further investigations in the next days, but I just wanted to give you an update so far. Regarding the debugging: {reason: "setup"}
{reason: "observer-emit", data: ""}
{reason: "start-loading"}
{reason: "mount-image"}
{reason: "loading-succeeded"}
{reason: "finally"} The following navigation then only have these events logged: {reason: "setup"}
{reason: "observer-emit", data: ""} The rest only gets logged after I scroll. |
You are getting the The main issue seems to be (as you already pointed out) the fact that the old page is still in the DOM after a route change. What version of Angular are you using? |
@zZeepo is there any chance that I can get access to your codebase or if you have been able to create a simple app where you reproduce the issue? |
Hey
My application was running with 9.0.0.
Unfortunately the repository is private and I can not share the code. So far I've tried the following with no success:
Will try to figure out the difference between my and the example app and keep you up to date. |
Ok, finally!
- LazyLoadImageModule.forRoot(intersectionObserverPreset)
+ LazyLoadImageModule.forRoot({
+ preset: scrollPreset,
+ }),
+ BrowserAnimationsModule, |
Thank you so much for the finding @zZeepo! ngAfterViewChecked() {
window.dispatchEvent(new CustomEvent('scroll', {}))
// or somthing like:
this.mySubject.emit({});
} It might be possible to add this extra event emitter in LazyLoadImageModule.forRoot({
preset: scrollPreset,
extraCheck: ['ngAfterViewChecked']
}) But it will add some complexity and I'm not sure it is worth it. You said you should give |
Yes I did. Since we have identified the source and figured out a decent workaround for the issue: |
Thank you so much for the investigation @zZeepo! |
No problem! I'm happily using this repo in my project. |
I added a link to this issue in the readme. Thanks once again. |
Hey,
thanks for this repo.
Really useful and generally well working!
I only ran into one problem in my application:
The problem occurs after switching to a new route in my application.
After the initial load of the app everything loads as expected, but for all following navigations the images are not loading in the newly rendered page. Once I scroll on the new route all images load correctly. This problem only occurs when using
preset: scrollPreset
. If I switch to the IntersectionObserver, everything works as expected (except from some known IntersectionObserver browser issues).I did a bit of debugging and the following seems to be happening:
The isVisible() check runs as soon as Angular appends and initialized the new content of the new route at the end of the page. While this is happening the content of the previous page is still part in the DOM, occupying the viewport. Because of this, the isVisible() will never be true and no images are loaded.
Once the new route is fully loaded and the components of the previous route are removed, the isVisible() requires a scroll event to be executed again.
My application is running Angular 9.0.0.
Might be related to this: #433
For now I'm working with this workaround, but I'm not happy with it.
I use your directive inside of one broadly used component in my application.
Inside of this component I fire a custom fake scroll event to trigger another visibility check once everything is ready.
Let me know if I can assist in solving this.
The text was updated successfully, but these errors were encountered: