1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/packages/next/client/webpack-hot-middleware-client.js

33 lines
874 B
JavaScript
Raw Normal View History

import 'event-source-polyfill'
import connect from './dev-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
}