提交 01fa65d4 编写于 作者: T Tim Neutkens 提交者: Guillermo Rauch

Unregister old serviceworker code (#1304)

Bring back https://github.com/zeit/next.js/commit/1b9e8771ec569def1773040b68f404c2cbc9484e with a check for the prefetch serviceworker + if it is supported by the browser
上级 9e938293
...@@ -7,6 +7,24 @@ import { loadGetInitialProps, getLocationOrigin } from '../utils' ...@@ -7,6 +7,24 @@ import { loadGetInitialProps, getLocationOrigin } from '../utils'
import { _notifyBuildIdMismatch } from './' import { _notifyBuildIdMismatch } from './'
import fetch from 'unfetch' 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 { export default class Router extends EventEmitter {
constructor (pathname, query, { Component, ErrorComponent, err } = {}) { constructor (pathname, query, { Component, ErrorComponent, err } = {}) {
super() super()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册