-
Notifications
You must be signed in to change notification settings - Fork 115
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
Update ServiceWorker if its href or scope changes #747
Conversation
03713a3
to
ab96860
Compare
* No code changes * Documenting the current state before I introduce a change in my next commit
* Moved logic into smaller parts that is used the generate the full href for the OneSignal ServiceWorker. - No result changes. * Simplied the else part where we check for ServiceWorkerActiveState - As we always want to install service worker A in all other cases. * The benifits of this refactor will be used in the next commit
24c2251
to
873a47a
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.
Would be nice if there was more background about the problem this is trying to solve and ServiceWorker state it results. Such as keeping the existing worker incase it has more than just a OneSignal importScripts in it. And how getting calling getRegistration("/scope") will get higher scope if a specific one isn't present.
src/managers/ServiceWorkerManager.ts
Outdated
|
||
return permission === "granted"; | ||
// 5. We have a OneSignal ServiceWorker installed, but did the path or scope of the ServiceWorker change? | ||
if (await this.changedServiceWorkerParams()) { |
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.
Future PR: ServiceWorkerActiveState.ThirdParty
check isn't really needed if we are checking for the name already in this changedServiceWorkerParams
method.
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.
Future PR: ServiceWorkerActiveState.None
could also be cleaned up, since this checks for presence. Consider if it is worth keeping enum however so it is easy to search for.
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.
Reviewed 1 of 1 files at r1, 5 of 6 files at r2, 1 of 1 files at r3.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @jkasten2 and @rgomezp)
src/managers/ServiceWorkerManager.ts, line 176 at r2 (raw file):
Previously, jkasten2 (Josh Kasten) wrote…
Future PR:
ServiceWorkerActiveState.None
could also be cleaned up, since this checks for presence. Consider if it is worth keeping enum however so it is easy to search for.
👍
* Added a new changedServiceWorkerParams method which check if; - OneSignal ServiceWorker path, filename, or query params changed. - OneSignal ServierWorker scope changed * This is a new check that was added to shouldInstallWorker * A developer might change the OneSignal service worker params to take advantage of the PR #745 "Remove ServiceWorker Page Control Requirement" - This way the new OneSignal SW scope can be setup while their new root scoped SW can be installed at the same time.
* Multiple service workers are possible with browsers, if their scopes are different. Updated the mock to handle this.
* MockServiceWorkerContainer.getRegistration - Added match any SW's that are at a higher scope than the one we are querying for as they are under it's control. - This was observed behavoir when testing on real browsers.
575d45d
to
e1b89b1
Compare
Description
1 Line Summary
Update ServiceWorker if its href or scope changes. Allows a seamless transition for those who take advantage of the "Remove ServiceWorker Page Control Requirement" changes.
Details
Systems Affected
Validation
Tests
Tested the following scenario:
OneSignal.SERVICE_WORKER_PARAM
to/push/onesignal/
navigator.serviceWorker.register("pwa-sw.js");
to replace OneSignal at the root scope.Tested on Edge and Firefox on Windows 10.
Info
Checklist
Programming Checklist
Interfaces:
Functions:
Typescript:
Other:
elem of array
syntax. PreferforEach
or usemap
context
if possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.context
Info
Browser behavior
Question if two different SW files have
self.addEventListener('push'
which one gets the event?Every
ServiceWorkerRegistration
instance has its own subscription endpoint. So the answer is simply which one you sent the push to..Checklist
/push/onesignal/
importScripts
and ours, want to migrate to OneSignal being under it own scope.Related Tickets
PR #745
This change is