-
Notifications
You must be signed in to change notification settings - Fork 26.6k
feat(service-worker): change default SW strategy behavior #35870
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
Conversation
21e583d
to
0749d35
Compare
You can preview 21e583d at https://pr35870-21e583d.ngbuilds.io/. |
Thx, @sonukapoor, for taking this on. Can you please remove the formatting changes? They make the PR hard to review and the formatter is unhappy (you are probably running the wrong commands locally if Also, how are you running the tests locally? The failures on CI seem expected. |
@gkalpak. I am running yarn lint and yarn test in the aio folder. When I try to run similar commands within root then I get all kind of strange errors from bazel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some more comments from a preliminary high-level review.
These changes are outside the |
0749d35
to
5d6531f
Compare
You can preview 5d6531f at https://pr35870-5d6531f.ngbuilds.io/. |
6be81b0
to
4b8b57a
Compare
You can preview 4b8b57a at https://pr35870-4b8b57a.ngbuilds.io/. |
afcdf51
to
50115ca
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…stration strategy Previously, when using the `registerWhenStable` ServiceWorker registration strategy (which is also the default) Angular would wait indefinitely for the [app to stabilize][1], before registering the ServiceWorker script. This could lead to a situation where the ServiceWorker would never be registered when there was a long-running task (such as an interval or recurring timeout). Such tasks can often be started by a 3rd-party dependency (beyond the developer's control or even without them realizing). In addition, this situation is particularly hard to detect, because the ServiceWorker is typically not used during development and on production builds a previous ServiceWorker instance might be already active. This commit enhances the `registerWhenStable` registration strategy by adding support for an optional `<timeout>` argument, which guarantees that the ServiceWorker will be registered when the timeout expires, even if the app has not stabilized yet. For example, with `registerWhenStable:5000` the ServiceWorker will be registered as soon as the app stabilizes or after 5 seconds if the app has not stabilized by then. Related to angular#34464. [1]: https://angular.io/api/core/ApplicationRef#is-stable-examples
…SW registration strategy
…p never stabilizes Previously, when using the default ServiceWorker registration strategy Angular would wait indefinitely for the [app to stabilize][1], before registering the ServiceWorker script. This could lead to a situation where the ServiceWorker would never be registered when there was a long-running task (such as an interval or recurring timeout). Such tasks can often be started by a 3rd-party dependency (beyond the developer's control or even without them realizing). In addition, this situation is particularly hard to detect, because the ServiceWorker is typically not used during development and on production builds a previous ServiceWorker instance might be already active. This commit fixes this by changing the default registration strategy from `registerWhenStable` to `registerWhenStable:30000`, which will ensure that the ServiceWorker will be registered after 30s at the latest, even if the app has not stabilized by then. Fixes angular#34464
… the app never stabilizes
…g app stabilization Previously, some of the built-in ServiceWorker registration strategies, namely `registerWithDelay:<timeout>` and `registerWhenStable:<timeout>`, would register potentially long-running timeout, thus preventing the app from stabilizing before the timeouts expired. This was especially problematic for the `registerWhenStable:<timeout>` strategy, which waits for the app to stabilize, because the strategy itself would prevent the app from stabilizing and thus the ServiceWorker would always be registered after the timeout. This commit fixes this by subscribing to the registration strategy observable outside the Angular zone, thus not affecting the app's stabilization.
50115ca
to
5bf2fe2
Compare
Rebased on master, updated commit messages and fixed up commits. Let's see what CI thinks 😃 |
Looks good to me. Thanks for the updates - very much appreciated. |
You can preview 5bf2fe2 at https://pr35870-5bf2fe2.ngbuilds.io/. |
…ffecting app stabilization
5bf2fe2
to
22bf4cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, @sonukapoor ✨
You can preview 22bf4cf at https://pr35870-22bf4cf.ngbuilds.io/. |
…p never stabilizes (#35870) Previously, when using the default ServiceWorker registration strategy Angular would wait indefinitely for the [app to stabilize][1], before registering the ServiceWorker script. This could lead to a situation where the ServiceWorker would never be registered when there was a long-running task (such as an interval or recurring timeout). Such tasks can often be started by a 3rd-party dependency (beyond the developer's control or even without them realizing). In addition, this situation is particularly hard to detect, because the ServiceWorker is typically not used during development and on production builds a previous ServiceWorker instance might be already active. This commit fixes this by changing the default registration strategy from `registerWhenStable` to `registerWhenStable:30000`, which will ensure that the ServiceWorker will be registered after 30s at the latest, even if the app has not stabilized by then. Fixes #34464 PR Close #35870
…g app stabilization (#35870) Previously, some of the built-in ServiceWorker registration strategies, namely `registerWithDelay:<timeout>` and `registerWhenStable:<timeout>`, would register potentially long-running timeout, thus preventing the app from stabilizing before the timeouts expired. This was especially problematic for the `registerWhenStable:<timeout>` strategy, which waits for the app to stabilize, because the strategy itself would prevent the app from stabilizing and thus the ServiceWorker would always be registered after the timeout. This commit fixes this by subscribing to the registration strategy observable outside the Angular zone, thus not affecting the app's stabilization. PR Close #35870
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. |
Previously, there was a chance that the SW will never register
when there is a long-running task or recurring timeout. This commit
fixes this, by first trying to wait for the app to stabilize, however,
if that does not happen, then the SW will register after 30 seconds.
Closes #34464
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #34464
What is the new behavior?
Does this PR introduce a breaking change?
Other information