rsnext/packages/next/client/dev/webpack-hot-middleware-client.js
Tim Neutkens 7e7f2c0a6d
Simplify a few parts of the codebase (#7506)
* Move client-side dev JS to dev folder

* Move eventsource polyfill

* Move source-map-support

* Move error boundary

* Deprecate Container in _app

* Make initialRender check better

* Remove unused code

* Only support one subscription as there is only one

* Don’t spread object

* Shorten property name

* Add container in development too

* Simplify query update logic
2019-06-05 20:15:42 +02:00

35 lines
864 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
}