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
Expose more events from service worker update cycle #39840
Comments
This sounds reasonable. The current update notification workflow is indeed less than ideal. FWIW, you can have a little more control by calling SwUpdate#checkForUpdate() explicitly (instead of relying on the SW to check for updates automatically). While Then by subscribing to If the promise returned by
There is no straight-forward way to distinguish the two, but if an error occurred the SW would have entered a degraded mode. So, you can determine what happened by requesting fetch('ngsw/state').
then(res => res.text()).
then(res => /Driver state: (\w+)/.exec(res)[1]) You can read more about the available debug options here. I am going to leave it open as a feature request, but it is not a high priority. If anyone wants to take it on, I would be happy to help/review. |
Thanks for a very helpful comment @gkalpak. What you're saying makes a lot of sense and it's definitely something that we're going to try. I'm also glad you find the feature request reasonable, I'll try to find some time and produce a PR |
Hello, I was asked to post my ideas here :) This feature request is for @angular/service-worker The current API is not very user-friendly. So far, in order to check for updates, I have to do the following:
How I would like the API to be:
Does this make sense? Cheers |
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage. We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package. You can find more details about the feature request process in our documentation. |
@gkalpak Is it possible to provide a PR although the Issue got insufficient votes? If your answer is yes, do you have a suggestion for the API or should I provide an Idea? |
While this got insufficient votes, I do believe it is a useful addition (esp. since the current implementation is a little unintuitive). I don't have any concrete API suggestions, but feel free to go ahead a make one (and provide a PR) 😉 |
Sorry for my long response time. Here is my suggestion for the API modifications: I would add a new field to NgUpdate:
This should meet the Same is for Regarding @TheParad0X comment: I guess sticking to Promises is fine here as Observables would require a call to And for TBH I am not sure if returning the events is the best way here. If an error is thrown in case of failure, returning a @gkalpak WDYT? |
Thx for putting this together, @spike-rabbit. I took some time to (briefly) think about the API today, so here are my thoughts. First of all, as a point of reference, here is what the class SwUpdate {
available: Observable<UpdateAvailableEvent>;
activated: Observable<UpdateActivatedEvent>;
unrecoverable: Observable<UnrecoverableStateEvent>;
isEnabled: boolean;
checkForUpdate(): Promise<void>;
activateUpdate(): Promise<void>;
}
Trying to stay as backwards compatible as possible, I might propose the following changes to the
With that, the class SwUpdate {
/** @deprecated */
available: Observable<UpdateAvailableEvent>;
/** @deprecated */
activated: Observable<UpdateActivatedEvent>;
versionUpdates: Observable<VersionDetectedEvent | VersionInstallationFailedEvent | VersionReadyEvent>;
unrecoverable: Observable<UnrecoverableStateEvent>;
isEnabled: boolean;
checkForUpdate(): Promise<boolean>;
activateUpdate(): Promise<boolean>;
} WDYT, @spike-rabbit, @marcinowski, others? |
Thx a lot @gkalpak. Your proposal would perfectly fit our needs. UnfortunateIy I cannot either come up with better names for the new Observables and it's events. Unless you will implement this, I could provide a PR in the second half of september. |
I certainly won't get to it any time soon, so feel free to submit a PR 😉 |
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>` which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding event to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Variable declaration adjustments might be necessary. The new return type simplifies to way for developers to obtain the outcome of these operations.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application the get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>` which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding event to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Variable declaration adjustments might be necessary. The new return type simplifies to way for developers to obtain the outcome of these operations.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>` which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding event to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Variable declaration adjustments might be necessary. The new return type simplifies to way for developers to obtain the outcome of these operations.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>` which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding event to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: Return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Variable declaration adjustments might be necessary. The new return type simplifies to way for developers to obtain the outcome of these operations. DEPRECATED: Deprecating `SwUpdate#activated` `SwUpdate#activated` is no longer needed can be replaced by using the return value of `SwUpdate#activateUpdate`.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: Deprecating `SwUpdate#availalbe` The new `SwUpdate#versionUpdate` can be used to rebuild `SwUpdate#availalbe`. Thus, `SwUpdate#availalbe` is no longer needed.
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>` which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding event to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: Return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Variable declaration adjustments might be necessary. The new return type simplifies to way for developers to obtain the outcome of these operations. DEPRECATED: Deprecating `SwUpdate#activated` `SwUpdate#activated` is no longer needed can be replaced by using the return value of `SwUpdate#activateUpdate`.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: Deprecating `SwUpdate#availalbe` The new `SwUpdate#versionUpdate` can be used to rebuild `SwUpdate#availalbe`. Thus, `SwUpdate#availalbe` is no longer needed.
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>`, which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding observable to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Although unlikely, it is possible that this change will cause TypeScript type-checking to fail in some cases. If necessary, update your types to account for the new return type. DEPRECATED: The `SwUpdate#activated` observable is deprecated. The `SwUpdate#activated` observable only emits values as a direct response to calling `SwUpdate#activateUpdate()` and was only useful for determining whether the call resulted in an update or not. Now, the return value of `SwUpdate#activateUpdate()` can be used to determine the outcome of the operation and therefore using `SwUpdate#activated` does not offer any benefit.
this commit introduces a new versionUpdate events which provide more information than the already existing `UpdateAvailableEvent`. These new events basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant.
This commit introduces a new `SwUpdate#versionUpdates` observalbe, which provides more granular information about Service Worker version updates than the already existing `SwUpdate#available` observable. The new events emitted by `SwUpdate#versionUpdates` basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant.
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>`, which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding observable to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Although unlikely, it is possible that this change will cause TypeScript type-checking to fail in some cases. If necessary, update your types to account for the new return type. DEPRECATED: The `SwUpdate#activated` observable is deprecated. The `SwUpdate#activated` observable only emits values as a direct response to calling `SwUpdate#activateUpdate()` and was only useful for determining whether the call resulted in an update or not. Now, the return value of `SwUpdate#activateUpdate()` can be used to determine the outcome of the operation and therefore using `SwUpdate#activated` does not offer any benefit.
This commit introduces a new `SwUpdate#versionUpdates` observalbe, which provides more granular information about Service Worker version updates than the already existing `SwUpdate#available` observable. The new events emitted by `SwUpdate#versionUpdates` basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant.
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>`, which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding observable to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Although unlikely, it is possible that this change will cause TypeScript type-checking to fail in some cases. If necessary, update your types to account for the new return type. DEPRECATED: The `SwUpdate#activated` observable is deprecated. The `SwUpdate#activated` observable only emits values as a direct response to calling `SwUpdate#activateUpdate()` and was only useful for determining whether the call resulted in an update or not. Now, the return value of `SwUpdate#activateUpdate()` can be used to determine the outcome of the operation and therefore using `SwUpdate#activated` does not offer any benefit.
This commit introduces a new `SwUpdate#versionUpdates` observalbe, which provides more granular information about Service Worker version updates than the already existing `SwUpdate#available` observable. The new events emitted by `SwUpdate#versionUpdates` basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant.
…pdate` should have a meaningful outcome Previously `activateUpdate` and `checkForUpdate` returned `Promise<void>`, which did not provide any information of the actual outcome of the operation. Developers needed to subscribe to a corresponding observable to obtain the outcome. With this commit `SwUpdate#activateUpdate` will return `Promise<boolean>` which resolves to `true` if an update was activated, to `false` if no new version is available and rejects in case of any error. `SwUpdate#checkForUpdate` also returns a `Promise<boolean>` which resolves to `true` if an update is available, to `false` if no update was found and rejects in case of any error. Closes angular#39840 BREAKING CHANGE: The return type of `SwUpdate#activateUpdate` and `SwUpdate#checkForUpdate` changed to `Promise<boolean>`. Although unlikely, it is possible that this change will cause TypeScript type-checking to fail in some cases. If necessary, update your types to account for the new return type. DEPRECATED: The `SwUpdate#activated` observable is deprecated. The `SwUpdate#activated` observable only emits values as a direct response to calling `SwUpdate#activateUpdate()` and was only useful for determining whether the call resulted in an update or not. Now, the return value of `SwUpdate#activateUpdate()` can be used to determine the outcome of the operation and therefore using `SwUpdate#activated` does not offer any benefit.
This commit introduces a new `SwUpdate#versionUpdates` observalbe, which provides more granular information about Service Worker version updates than the already existing `SwUpdate#available` observable. The new events emitted by `SwUpdate#versionUpdates` basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes angular#39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant.
This commit introduces a new `SwUpdate#versionUpdates` observalbe, which provides more granular information about Service Worker version updates than the already existing `SwUpdate#available` observable. The new events emitted by `SwUpdate#versionUpdates` basically add the possibility for application to get notified if a new version is available on the server (not yet downloaded) and if an installation of a new version failed. Closes #39840 DEPRECATED: The `SwUpdate#availalbe` observable is deprecated. The new `SwUpdate#versionUpdates` observable provides the same information and more. Therefore, it is possible to rebuild the same behavior as `SwUpdate#availalbe` using the events emitted by `SwUpdate#versionUpdates` and filtering for `VersionReadyEvent` events. As a result, the `SwUpdate#availalbe` observable is now redundant. PR Close #43668
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. |
🚀 feature request
Relevant Package
This feature request is for @angular/service-worker
Description
We are currently experiencing an issue with a significant percentage of our users using outdated versions of our application. We're not really sure whether they're taking a very long time to update their applications or is it more of a problem with detection of the new version or something else. We don't have enough data to determine whether there is an issue with our service worker implementation, an issue with our application or maybe some edge case in the framework. Currently the service worker exposes only the
available
andactivated
events. This gives only a bit of an insight on how does the service worker perform updates on the client side.Describe the solution you'd like
As mentioned before the service worker currently exposes only two events
Ideally the service would expose some additional events like
This would allow us to track those events, figure out why is it that some users are taking very long time to get the new version and/or maybe optimise some parts of the flow.
EDIT(gkalpak)
Related issue: #34397
The text was updated successfully, but these errors were encountered: