rsnext/packages/next/client/dev/webpack-hot-middleware-client.js
Joe Haddad 18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00

35 lines
865 B
JavaScript

import connect from './error-overlay/hot-dev-client'
export default ({ assetPrefix }) => {
const options = {
path: `${assetPrefix}/_next/webpack-hmr`,
}
const devClient = connect(options)
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
}