feat(service-worker): add option to config when to register sw#21842
feat(service-worker): add option to config when to register sw#21842JiaLiPassion wants to merge 8 commits intoangular:masterfrom
Conversation
|
Looks like the build failed with: |
|
Would going down a path similar to how preloading lazy loaded routes works be better? I.e. define a swRegistrationStrategy parameter that then has a couple of Angular provided defaults (like |
|
@Splaktar , thank you for review, I will update the PR and let you review again. |
|
@Splaktar , I have updated the PR, change the option to
I also update the sample at DevIntent/angular-example#1, please review. |
Splaktar
left a comment
There was a problem hiding this comment.
I like this direction that this is heading 😄
There was a problem hiding this comment.
Should the default delay be non-zero? Perhaps 5 or 10s? It would be better to give an intelligent default rather than falling back to just be the same as registerImmediately.
There was a problem hiding this comment.
the zero fallback is a little different with registerImmediately.
registerImmediatelymeans no delay at all.zeromeanssetTimeout(register, 0), it will still wait allmicroTasksto finish.
So I think maybe zero is acceptable. What do you think?
There was a problem hiding this comment.
Interesting, can you please specify those details about this default delay in the docs?
There was a problem hiding this comment.
You can pass some options to the register() method.
There was a problem hiding this comment.
Got it, I will remove the ` mark.
There was a problem hiding this comment.
Sorry, the ` is fine, I just added a "the".
There was a problem hiding this comment.
This formatting doesn't seem to be rendering properly in GitHub Markdown.
There was a problem hiding this comment.
The <code-tabs> and <code-pane> will be parsed by dgeni, I have tested locally, this part can be rendered correctly.
There was a problem hiding this comment.
I know that dgeni will code parse comments for addition to docs, but it also parses markdown?
There was a problem hiding this comment.
specify a strategy that determines when to register the service worker
There was a problem hiding this comment.
the service worker will register when the application is stable (no microTasks or macroTasks remain).
There was a problem hiding this comment.
got it, change Application to application.
There was a problem hiding this comment.
Added two "the"s in there too
There was a problem hiding this comment.
without waiting for the application to become stable
There was a problem hiding this comment.
got it, add the before application.
There was a problem hiding this comment.
registerDelay:timeout: register after the timeout period. timeout is the number of milliseconds to delay registration. For example: registerDelay:5000 would register the service worker after 5 seconds.
There was a problem hiding this comment.
A factory to get an Observable: You can also specify a factory which returns an Observable. The service worker will be registered the first time that a value is emitted by the Observable.
|
@alxhub we would love some feedback on this approach before more effort is spent on this. |
|
@Splaktar , thank you for the detailed review, I have updated the PR, and about the |
|
Hi @JiaLiPassion! This PR has merge conflicts due to recent upstream merges. |
1 similar comment
|
Hi @JiaLiPassion! This PR has merge conflicts due to recent upstream merges. |
|
@JiaLiPassion can you please rebase this? |
|
@Splaktar, sure, will do. |
|
It looks like the last commit broke the build due to TypeScript 3.1.x changes. |
|
Got it, I will fix it today. |
|
@Splaktar, I have updated the source, please review , thanks. |
|
LGTM! CI Tests now pass. Thank you. |
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
…tionOptions` This is in preparation of making `RegistrationOptions` part of the public API (in a subsequent commit).
…untime config 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.
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the ℹ️ Googlers: Go here for more info. |
|
|
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
…untime 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
|
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. |



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: #20970
Some times, angular will start up some long
macroTasksuch as a long delaysetTimeout(in #20970,firebase authwill start a200stimeout to do token refresh). songZonewill not become stable and will not triggerservice-workerto do registration.What is the new behavior?
I think there are so many cases that when startup, there will be
macroTasknot complete or cost a lot of time, so in this PR, my idea is add acallbackto let user to be able to choose when toregister.I added a property in
RegistrationOptions, the sample is here.DevIntent/angular-example#1
and
getServiceWorkerInitFactorywill return a promise, user can resolve it by their choice.the sample code is here,
Does this PR introduce a breaking change?
Other information
if the idea is ok, I will update the document.
This PR incorporates #26002.