-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed
Description
Describe the bug
CRA provides a script to use service worker. This script export a function to unregister it.
This function is called, by default, in the index file of the template. On MSW SW is used to intercept http calls and mock them, but because of the SW are unregistered on bootstrap it may cause some problem. Is this the correct behavior?
Maybe CRA should only unregister his SW.
The unregister function could be something like the following
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then((registrations) => {
registrations.forEach((registration) => {
if (registration?.active?.scriptURL.includes('service-worker.js')) {
registration.unregister()
}
})
})
}
}Expected behavior
unregister should remove only SW registered by CRA.
We have an issue here
Actual behavior
unregister is removing other SW.
kettanaito