2019-06-05 20:15:42 +02:00
|
|
|
import connect from './error-overlay/hot-dev-client'
|
2019-02-22 16:23:58 +01:00
|
|
|
|
2019-02-19 22:45:07 +01:00
|
|
|
export default ({ assetPrefix }) => {
|
2018-07-24 11:24:40 +02:00
|
|
|
const options = {
|
|
|
|
path: `${assetPrefix}/_next/webpack-hmr`
|
|
|
|
}
|
|
|
|
|
|
|
|
const devClient = connect(options)
|
2016-11-23 19:32:49 +01:00
|
|
|
|
2019-05-29 13:57:26 +02:00
|
|
|
devClient.subscribeToHmrEvent(obj => {
|
2019-01-08 23:10:32 +01:00
|
|
|
if (obj.action === 'reloadPage') {
|
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
if (obj.action === 'removedPage') {
|
|
|
|
const [page] = obj.data
|
|
|
|
if (page === window.next.router.pathname) {
|
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (obj.action === 'addedPage') {
|
|
|
|
const [page] = obj.data
|
2019-05-29 13:57:26 +02:00
|
|
|
if (
|
|
|
|
page === window.next.router.pathname &&
|
|
|
|
typeof window.next.router.components[page] === 'undefined'
|
|
|
|
) {
|
2019-01-08 23:10:32 +01:00
|
|
|
return window.location.reload()
|
|
|
|
}
|
|
|
|
return
|
2017-04-18 06:18:43 +02:00
|
|
|
}
|
2019-01-08 23:10:32 +01:00
|
|
|
throw new Error('Unexpected action ' + obj.action)
|
2017-04-18 06:18:43 +02:00
|
|
|
})
|
2018-07-24 11:24:40 +02:00
|
|
|
|
|
|
|
return devClient
|
2017-04-18 06:18:43 +02:00
|
|
|
}
|