-
Notifications
You must be signed in to change notification settings - Fork 58
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
Check if there is a worker that has been previously installed #8
Conversation
Will this fire the hook twice if:
|
Yes, if there is a newer version (e.g. version C). |
More precisely, this special situation occurs only before the user closes all clients (pages) in the same scope. The new worker will be automatically activated when the page is reopened in a new tab. |
@imyelo in that case I think it's better to ensure the hook is fired at most once for each session. |
Yeah, I understand your concern. But the above situation is really difficult for the users to find out when they only read the examples in the readme. Or maybe we can
|
I also encountered similar requirements a week ago and found this solution. And I still cannot find enough arguments for me to support this workaround. But there is one thing should be OK, when the synchronous value waiting exists, we shouldn't bind updatefound event. |
I just tested for that, when I omitted the first But |
Closed in favor of #9, thanks for the contribution! |
In a recent practice, I found that if developers use a
updated
hook to guide users to a new version, they tend to fall into a trap.Let me explain it with the following example steps:
register-service-worker
emits theupdated
hook, so we pop up a prompt on the page asking the user if they want to use the new version B. If the user chooses "yes", then we will activate the worker of version B by callingskipWaiting
, and then automatically refresh the page withwindow.location.reload
. In most cases, up to this point, everything is going the way we expect it to.waiting
state.So, what's the problem?
First, when version B is in the
waiting
state for the first time, simply refreshing the page does not activate B's worker. The reason for this is explained in this article:Second, we shouldn't call
skipWaiting
before the user confirms, which is also explained in the above article:Thus, we find that in this case, when the new worker has entered the waiting (to be activated) state, we are supposed to go into the process of guiding the user to update. However, we can not achieve it simply by listening to a specified hook.
IMO, is that this case should trigger the
updated
event, and that's whatupdated
is supposed to do.In addition, this example shows what developers need to do when
updated
event does not cover the above case:imyelo/pokequest-wiki@023bb81
What do you think? @yyx990803