Commit graph

61 commits

Author SHA1 Message Date
Joey Perrott
c4b880a025 refactor: migrate docs, examples, private, service worker and upgrade to prettier formatting (#54163)
Migrate formatting to prettier for docs, examples, private, service worker and upgrade from clang-format

PR Close #54163
2024-01-30 20:08:40 +00:00
Matthieu Riegler
7800a3c9f5 refactor(core): remove InjectionToken descriptions in optimized builds. (#53747)
We started guarding the `InjectionToken` descriptions with `ngDevMode`. Let's generalize that accross the FW.

PR Close #53747
2024-01-26 19:12:41 +00:00
Charles Lyding
e149ebf228 build: update rxjs build version to v7 (#53500)
The version of rxjs used to build the repository has been updated to v7.
This required only minimal changes to the code. Most of which were type
related only due to more strict types in v7. The behavior in those cases
was left intact. The most common type related change was to handle the
possibility of `undefined` with `toPromise` which was always possible with
v6 but the types did not reflect the runtime behavior. The one change that
was not type related was to provide a parameter value to the `defaultIfEmpty`
operator. It no longer defaults to a value of `null` if no default is provided.
To provide the same behavior the value of `null` is now passed to the operator.

PR Close #53500
2023-12-18 16:25:37 +00:00
Matthieu Riegler
a645ceca94 refactor(service-worker): Remove deprecated activated & available observables. (#49498)
`activated`and `available` were deprecated by #43535 in v13.

PR Close #49498
2023-10-10 11:54:07 -07:00
Julien Saguet
5e7fc259ea feat(service-worker): add function to provide service worker (#48247)
add function `provideServiceWorker` to register a service worker in standalone applications without using `ServiceWorkerModule.register()`

PR Close #48247
2023-03-09 18:13:50 +00:00
Matthieu Riegler
f2c8ac5335 refactor(service-worker): removing some todos (#48707)
Removing some outdated/unnecessary todos.

PR Close #48707
2023-01-24 16:40:23 +00:00
vyom1611
33bb34b64e refactor(service-worker): refactored code to remove useless code (#47255)
- Removes useless code in `generator.ts` and `module.ts` in service-workers
- Uses inline variables to return values from functions

PR Close #47255
2022-09-06 09:15:06 -07:00
George Kalpakas
c905da12e2 docs(service-worker): improve docs related to SwUpdate APIs (#46960)
This commit improves documentation related to recently improved or
deprecated `SwUpdate` APIs in the following ways:

- Update [check-for-update.service.ts][1] to make use of the return
  value of [SwUpdate#checkForUpdate()][2].
- Update [prompt-update.service.ts][3] to not call
  [SwUpdate#activateUpdate()][4] and just reload the page.
- Update the [SwUpdate#activateUpdate()][4] API docs to explain that it
  is only useful if you want to update a client without reloading and
  that it can easily lead to version skew.
- Update [a code-snippet][5] to no longer be [hard-coded][6].

[1]: 9d9d05911d/aio/content/examples/service-worker-getting-started/src/app/check-for-update.service.ts (L16)
[2]: https://angular.io/api/service-worker/SwUpdate#checkForUpdate
[3]: 9d9d05911d/aio/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts (L15)
[4]: https://angular.io/api/service-worker/SwUpdate#activateUpdate
[5]: 96c6139c9a/packages/service-worker/src/update.ts (L44-L54)
[6]: https://angular.io/guide/docs-style-guide#hard-coded-snippets

Fixes #43665

PR Close #46960
2022-09-06 09:11:57 -07:00
FatalMerlin
76a1b04305 refactor(service-worker): formatting of index.ts (#47044)
Fixed formatting of index.ts.

PR Close #47044
2022-08-18 12:09:10 -07:00
Merlin
46fa1a7a13 fix(service-worker): export NoNewVersionDetectedEvent (#47044)
NoNewVersionDetectedEvent is marked as @publicApi but not exported.
PR Close #47044
2022-08-18 12:09:10 -07:00
George Kalpakas
4478dff471 docs(service-worker): improve description of NoNewVersionDetectedEvent (#45266)
The `NoNewVersionDetectedEvent` does not imply that the latest version
on the server is the same as the version the client is on (because a
client could be on an older version).

Update the description of the event to better describe what it actually
means (i.e. that the SW didn't find a version it didn't already know
about, but without implying anything about the version the current
client is using).

PR Close #45266
2022-03-08 10:26:05 -08:00
Joey Perrott
bd04fbc05b feat(service-worker): emit a notification when the service worker is already up to date after check (#45216)
When the service worker checks for an update and finds that the version on the server is the same as
the version locally installed, it currently noops.  This change introduces an event which it emits
in this situation which notifies clients a check has occurred without error and no update was found.

PR Close #45216
2022-03-03 12:29:04 -08:00
Maximilian Köller
0dc45446fe feat(service-worker): expose more version update events (#43668)
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
2021-10-05 11:00:07 -07:00
Maximilian Köller
59225f5586 feat(service-worker): SwUpdate#activeUpdate and SwUpdate#checkForUpdate should have a meaningful outcome (#43668)
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 #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.

PR Close #43668
2021-10-05 11:00:07 -07:00
George Kalpakas
a8698ce802 docs(service-worker): add missing comma in example JSON data (#42606)
PR Close #42606
2021-07-08 10:27:16 -07:00
codingnuclei
d546501ab5 feat(service-worker): add openWindow, focusLastFocusedOrOpen and navigateLastFocusedOrOpen (#42520)
Add `openWindow`, `focusLastFocusedOrOpen` and `navigateLastFocusedOrOpen` abilty to the notificationclick handler such that when either a notification or notification action is clicked the service-worker can act accordinly without the need for the app to be open

PR Close #26907

PR Close #42520
2021-06-23 16:31:09 +00:00
Hoel IRIS
21bc16d4d8 fix(service-worker): handle error with console.error (#40236)
This commit reverts commit [_fix(service-worker): handle error with
ErrorHandler_](https://github.com/angular/angular/pull/39990/commits/552419d).

With Angular v11.0.4 and commit [_fix(service-worker): handle error with
ErrorHandler_](https://github.com/angular/angular/pull/39990/commits/552419d)
Angular start to send all service worker registration errors to the Angular
standard `ErrorHandler#handleError()` interface, instead of logging them in the
console.
But users existing `ErrorHandler#handleError()` implementations are not adapted
to service worker registration errors and it might result in broken apps or
bad UI.
Passing to `ErrorHandler` is desirable for some and undesirable for others and
the same is true for passing to `console.error()`.
But `console.error()` was used for a long time and thus it is preferable to keep
it as long as a good solution is not found with `ErrorHandler`.

Right now it's hard to define a good solution for `ErrorHandler` because:

1. Given the nature of the SW registration errors (usually outside the control
   of the developer, different error messages on each browser/version, often
   quite generic error messages, etc.), passing them to the `ErrorHandler` is
   not particularly helpful.
2. While `ErrorHandler#handleError()` accepts an argument of type `any` (so
   theoretically we could pass any object without changing the public API), most
   apps expect an `Error` instance, so many apps could break if we changed the
   shape.
3. Ideally, the Angular community want to re-think the `ErrorHandler` API
   and add support for being able to pass additional metadata for each error
   (such as the source of the error or some identifier, etc.). This change,
   however, could potentially affect many apps out there, so the community must
   put some thought into it and design it in a way that accounts for the needs
   of all packages (not just the SW).
4. Given that we want to more holistically revisit the `ErrorHandler` API, any
   changes we make in the short term to address the issue just for the SW will
   make it more difficult/breaky for people to move to a new API in the future.

To see the whole explanation see GitHub PR #40236.

PR Close #40236
2021-01-25 10:11:58 -08:00
Christoph Guttandin
74e42cf7d5 fix(service-worker): handle error with ErrorHandler (#39990)
Errors thrown by calling serviceWorker.register() are now passed to the global ErrorHandler.

Fixes #39913

PR Close #39990
2020-12-08 12:03:27 -08:00
Sonu Kapoor
0fc2bef0cd docs(service-worker): add links to service worker communication guide (#36847)
PR Close #36847
2020-08-31 11:41:16 -07:00
Sonu Kapoor
036a2faf02 feat(service-worker): add UnrecoverableStateError (#36847)
In several occasions it has been observed when the browser has evicted
eagerly cached assets from the cache and which can also not be found on the
server anymore. This can lead to broken state where only parts of the application
will load and others will fail.

This commit fixes this issue by checking for the missing asset in the cache
and on the server. If this condition is true, the broken client will be
notified about the current state through the `UnrecoverableStateError`.

Closes #36539

PR Close #36847
2020-08-31 11:41:11 -07:00
George Kalpakas
24b420527a docs(service-worker): fix typos in SwRegistrationOptions API docs (#38047)
PR Close #38047
2020-07-15 13:10:25 -07:00
George Kalpakas
bcc0a035cc docs(service-worker): update default value of SwRegistrationOptions#registrationStrategy (#37555)
The default value was changed from `registerWhenStable` to
`registerWhenStable:30000` in 29e8a64cf0,
but the decumentation was not updated to reflect that.

This commit updates the documentation to mention the correct default
value.

PR Close #37555
2020-06-15 09:48:55 -07:00
Joey Perrott
d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00
Joey Perrott
698b0288be build: reformat repo to new clang@1.4.0 (#36613)
PR Close #36613
2020-04-14 12:08:36 -07:00
Sonu Kapoor
2d7c95fb70 fix(service-worker): prevent SW registration strategies from affecting 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
2020-03-27 10:47:44 -07:00
Sonu Kapoor
29e8a64cf0 fix(service-worker): by default register the SW after 30s even the app 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
2020-03-27 10:47:44 -07:00
Sonu Kapoor
00efacf561 feat(service-worker): support timeout in registerWhenStable SW registration strategy (#35870)
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 #34464.

[1]: https://angular.io/api/core/ApplicationRef#is-stable-examples

PR Close #35870
2020-03-27 10:47:44 -07:00
George Kalpakas
65aaffcfe4 docs(service-worker): add example app for SwPush API docs (#32139)
Previously, the `SwPush` API docs were using hard-coded code snippets.

This commit switches to using code snippets from an actual example app,
which ensures that the code shown in the docs will at least continue to
compile successfully.

PR Close #32139
2019-08-27 16:18:53 -07:00
Judy Bogart
ac11a0be15 docs: add push notification usage to api doc (#32139)
PR Close #32139
2019-08-27 16:18:53 -07:00
George Kalpakas
1bcd58cee8 refactor(docs-infra): remove linenums=false since it is now the default (#31674)
PR Close #31674
2019-07-24 14:38:54 -07:00
Paul Gschwendtner
69a612d402 refactor(service-worker): ensure compatibility with typescript strict flag (#30993)
As part of FW-1265, the `@angular/service-worker` package is made compatible
with the TypeScript `--strict` flag. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html)

PR Close #30993
2019-07-18 14:21:26 -07:00
Hoel IRIS
81c2a94310 fix(service-worker): avoid uncaught rejection warning when registration fails (#30876)
Service worker API `navigator.serviceWorker.register` can fail in multiple ways.
For example, in Chrome, with an unstable network connection you can have the
following error: `An unknown error occurred when fetching the script.`

In the current state, it creates an `Uncaught (in promise) TypeError:` style of
error, which cannot be caught by the user on his own.

I think it's better to log the error over raising an error that cannot be
caught.

PR Close #30876
2019-06-07 08:46:25 -07:00
George Kalpakas
8f120aff33 refactor(service-worker): DRY up SW registration logic (#21842)
PR Close #21842
2019-04-25 12:29:58 -07:00
JiaLi.Passion
4cfba58072 feat(service-worker): allow configuring when the SW is registered (#21842)
Fixes #20970

PR Close #21842
2019-04-25 12:29:58 -07:00
George Kalpakas
aa53d6cc6d docs(service-worker): improve SwRegistrationOptions docs and add example (#21842)
PR Close #21842
2019-04-25 12:29:58 -07:00
deebloo
39c0152b76 feat(service-worker): expose SwRegistrationOptions token to allow runtime config (#21842)
Previously, the ServiceWorker registration options should be defined as
an object literal (in order for them to be compatible with Ahead-of-Time
compilation), thus making it impossible to base the ServiceWorker
behavior on runtime conditions.
This commit allows specifying the registration options using a regular
provider, which means that it can take advantage of the `useFactory`
option to determine the config at runtime, while still remaining
compatible with AoT compilation.

PR Close #21842
2019-04-25 12:29:58 -07:00
George Kalpakas
d7887ab4ab refactor(service-worker): rename RegistrationOptions to SwRegistrationOptions (#21842)
This is in preparation of making `RegistrationOptions` part of the
public API (in a subsequent commit).

PR Close #21842
2019-04-25 12:29:58 -07:00
joostme
aca8ea9c0b refactor(service-worker): Format comments and add additional test (#25860)
- Format JSDoc for notificationClicks
- Add comment on why handleClick does not use hasOwnProperty
- Add additional test that uses handleClick without action

PR Close #25860
2018-11-01 15:13:33 -07:00
Joost Zöllner
4a01ada291 fix(service-worker): Fix public api guard typing (#25860)
PR Close #25860
2018-11-01 15:13:33 -07:00
Joost Zöllner
10618752e6 fix(service-worker): Add typing to public api guard and fix lint errors (#25860)
PR Close #25860
2018-11-01 15:13:33 -07:00
Joost Zöllner
c78c221028 feat(service-worker): Add typing for messagesClicked in SwPush service (#25860)
- Properly type messagesClicked Observable stream
- Add new NotificationObject interface

PR Close #25860
2018-11-01 15:13:32 -07:00
Joost Zoellner
cf6ea283bb feat(service-worker): handle 'notificationclick' events (#25860)
The previous version did not support the 'notificationclick' event.
Add event handler for the event and provide an observable of
clicked notifications in the SwPush service.

Closes #20956, #22311

PR Close #25860
2018-11-01 15:13:32 -07:00
Pete Bacon Darwin
24521f549c docs: convert all @experimental tags to @publicApi tags (#26595)
PR Close #26595
2018-10-19 14:35:52 -07:00
George Kalpakas
bfeed842ee docs(service-worker): improve API docs for SwPush/SwUpdate (#23138)
PR Close #23138
2018-10-05 13:48:14 -07:00
George Kalpakas
77942cc690 refactor(service-worker): simplify/improve NgswCommChannel typings (#23138)
PR Close #23138
2018-10-05 13:48:14 -07:00
George Kalpakas
7aed64d3a1 docs(service-worker): add UpdateActivated/AvailableEvent to the public API (#23138)
PR Close #23138
2018-10-05 13:48:14 -07:00
Alex Eagle
cbbad1b791 refactor(ivy): pre-factor: set explicit type parameters for ModuleWithProviders (#25970)
Ivy depends on having the generic type token later when reading the ModuleWithProviders from a .d.ts file.

PR Close #25970
2018-09-18 13:28:44 -07:00
Rado Kirov
c95437f15d build(bazel): Turning on strictPropertyInitialization for Angular. (#24572)
All errors for existing fields have been detected and suppressed with a
`!` assertion.

Issue/24571 is tracking proper clean up of those instances.

One-line change required in ivy/compilation.ts, because it appears that
the new syntax causes tsickle emitted node to no longer track their
original sourceFiles.

PR Close #24572
2018-06-25 07:57:13 -07:00
George Kalpakas
3ed2d75336 fix(service-worker): fix SwPush.unsubscribe() (#24162)
Fixes #24095

PR Close #24162
2018-06-11 14:04:30 -04:00
George Kalpakas
4d55dfd9d9 test(service-worker): allow SwPush tests to run on Node.js (#24162)
PR Close #24162
2018-06-11 14:04:30 -04:00