1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Unregister old serviceworker code (#1304)

Bring back 1b9e8771ec with a check for the prefetch serviceworker + if it is supported by the browser
This commit is contained in:
Tim Neutkens 2017-02-27 20:15:39 +01:00 committed by Guillermo Rauch
parent 9e9382936c
commit 01fa65d4a2

View file

@ -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()