-
Notifications
You must be signed in to change notification settings - Fork 12k
Angular 5 service worker not work in some lazy load modules #9021
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
Comments
@Brocco do you know why this might be? @icepoint0 it would help if you can provide a repro we can follow. |
@filipesilva |
same thing happening to me right now! Trying my best to provide a sample repo for this. |
@warapitiya Follow me ,dude |
@icepoint0 Currently for me, its not working for all the modules. |
@warapitiya maybe you shoud try every module's route. to test which route will load the [service-worker].js ,:D , My route is /login, i am still waiting help , so just follow my github page. |
lol |
Tip: I figured that angular is not executing "serviceWorker.register()" function. The reason I'm saying this is because I'm not getting any request to Executing the below code snippet in console will register the service as expected. if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/ngsw-worker.js');
} This can be related to #9098 also. |
Ok, I think now I fixed it. Issue was directly adding Solution: Instead of adding the JS file directly, More info: https://juristr.com/blog/2018/01/ng-app-runtime-config/ |
i will try, thank u . @warapitiya |
Just to chime in here... I'm experiencing this on some child routes of a lazy-loaded module. I think the offending library for me is https://github.com/chenqingspring/ng-lottie. @filipesilva do you still need repro steps for this? I think I can come up with a fairly simple example as a demonstration using that library. Just like @warapitiya, the
in my console to load the service worker. |
I'm updating here after I've done some analysis. It looks like the offending code is: Looks like this error is almost always a result of a fault in a third-party module causing the app to never mark "isStable" to true, thus causing the observable to trigger, and thus the serviceworker.register(); While I don't think this is a problem with @angular/angular-cli or @angular/service-worker, I think there may be some need to explain to third-party devs how to prevent this scenario. There was another library that was causing this in late 2017, and here is the relevant issue: angular/angularfire#1347 Additionally, here's an issue in @angular/angular-cli that references I think a similar result. #8779 Finally, in my particular case, I think the offending line in airbnb/lottie is https://github.com/airbnb/lottie-web/blob/master/build/player/lottie.js#L4184 Somehow the xhr request is preventing the app from becoming stable. If anyone is more familiar ng "app stability", I think this can fairly easily be resolved. |
Heya, is this still a problem? If so, I would like to see a repro so that we could get some traction on it. |
…pening when I have lazy modules. I found an open issue that can be the same problem: github.com/angular/angular-cli/issues/9021
I have the same problem...
my post-routing.module is:
When I'm running the lightHouse with this configuration all check is failing, but if I to remove the lazy module together with the redirect configuration. All check is passing. |
Thanks for reporting this issue. However, you didn't provide sufficient information for us to reproduce the problem. Please check out our submission guidelines to understand why we can't act on issues that are lacking important information. If the problem persists, please file a new issue and ensure you provide all of the required information when filling out the issue template. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The example websitepage :https://kl.atyun.net
If u first load the websites it will redirect to module A ,and the route is '/sites', but the service worker not work in this route. and then u visit the page "/login" ,service worker works now ,why ?
"/login" and "/sites" not in same chunk.
and here is my code:
app.module:
routing config:
The text was updated successfully, but these errors were encountered: