rsnext/packages/next/client/dev/webpack-hot-middleware-client.js

32 lines
774 B
JavaScript
Raw Normal View History

import connect from './error-overlay/hot-dev-client'
export default () => {
const devClient = connect()
2020-05-18 21:24:37 +02:00
devClient.subscribeToHmrEvent((obj) => {
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
if (
page === window.next.router.pathname &&
typeof window.next.router.components[page] === 'undefined'
) {
return window.location.reload()
}
return
}
throw new Error('Unexpected action ' + obj.action)
})
return devClient
}