Skip to content

Commit

Permalink
Unregister old serviceworker code (#1304)
Browse files Browse the repository at this point in the history
Bring back 1b9e877 with a check for the prefetch serviceworker + if it is supported by the browser
  • Loading branch information
timneutkens authored and rauchg committed Feb 27, 2017
1 parent 9e93829 commit 01fa65d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import { loadGetInitialProps, getLocationOrigin } from '../utils'
import { _notifyBuildIdMismatch } from './'
import fetch from 'unfetch'

if (typeof window !== 'undefined' && typeof navigator.serviceWorker !== 'undefined') {
navigator.serviceWorker.getRegistrations()
.then(registrations => {
registrations.forEach(registration => {
if (!registration.active) {
return
}

if (registration.active.scriptURL.indexOf('_next-prefetcher.js') === -1) {
return
}

console.warn(`Unregistered deprecated 'next/prefetch' ServiceWorker. See https://github.com/zeit/next.js#prefetching-pages`)
registration.unregister()
})
})
}

export default class Router extends EventEmitter {
constructor (pathname, query, { Component, ErrorComponent, err } = {}) {
super()
Expand Down

0 comments on commit 01fa65d

Please sign in to comment.