Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1707 from blockstack/hotfix/unregister-legacy-sw.js
Browse files Browse the repository at this point in the history
Add check for legacy sw.js
  • Loading branch information
yknl authored Sep 30, 2018
2 parents e4cdacb + 40a037b commit 84ec3e2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ configureLogging(
if (process.env.NODE_ENV === 'production' && process.env.WEBAPP) {
if ('serviceWorker' in navigator) {
window.addEventListener('load', async () => {
// if we have registrations and one is at /sw.js, unregister it.
const registrations = await navigator.serviceWorker.getRegistrations()
if (registrations && registrations.length) {
registrations.forEach(async registration => {
if (
registration.active &&
registration.active.scriptURL &&
!registration.active.scriptURL.includes('static')
) {
logger.debug('Unregistering legacy service worker')
await registration.unregister()
}
})
}
// continue to register our service worker
try {
const registration = await navigator.serviceWorker.register(
'/static/js/sw.js'
Expand Down

0 comments on commit 84ec3e2

Please sign in to comment.