Unverified Commit 986f648b authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Unify serverError hmr event (#54962)

Ensures only one name is used for the event, makes it easier to search for, going to replace this with the constant like the other events in a follow-up PR but this can be landed as-is.
parent be3a7e47
......@@ -11,54 +11,56 @@ export default () => {
window.next.router.pathname === '/404' ||
window.next.router.pathname === '/_error'
if (obj.action === 'reloadPage') {
sendMessage(
JSON.stringify({
event: 'client-reload-page',
clientId: window.__nextDevClientId,
})
)
return window.location.reload()
}
if (obj.action === 'removedPage') {
const [page] = obj.data
if (page === window.next.router.pathname || isOnErrorPage) {
switch (obj.action) {
case 'reloadPage': {
sendMessage(
JSON.stringify({
event: 'client-removed-page',
event: 'client-reload-page',
clientId: window.__nextDevClientId,
page,
})
)
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') ||
isOnErrorPage
) {
sendMessage(
JSON.stringify({
event: 'client-added-page',
clientId: window.__nextDevClientId,
page,
})
)
return window.location.reload()
case 'removedPage': {
const [page] = obj.data
if (page === window.next.router.pathname || isOnErrorPage) {
sendMessage(
JSON.stringify({
event: 'client-removed-page',
clientId: window.__nextDevClientId,
page,
})
)
return window.location.reload()
}
return
}
case 'addedPage': {
const [page] = obj.data
if (
(page === window.next.router.pathname &&
typeof window.next.router.components[page] === 'undefined') ||
isOnErrorPage
) {
sendMessage(
JSON.stringify({
event: 'client-added-page',
clientId: window.__nextDevClientId,
page,
})
)
return window.location.reload()
}
return
}
case 'serverError':
case 'devPagesManifestUpdate': {
return
}
default: {
throw new Error('Unexpected action ' + obj.action)
}
return
}
if (
obj.action === 'serverError' ||
obj.action === 'devPagesManifestUpdate'
) {
return
}
throw new Error('Unexpected action ' + obj.action)
})
return devClient
......
......@@ -17,7 +17,7 @@ export function pageBootrap(assetPrefix: string) {
let buildIndicatorHandler: (obj: Record<string, any>) => void = () => {}
function devPagesHmrListener(payload: any) {
if (payload.event === 'server-error' && payload.errorJSON) {
if (payload.action === 'serverError' && payload.errorJSON) {
const { stack, message } = JSON.parse(payload.errorJSON)
const error = new Error(message)
error.stack = stack
......
......@@ -949,8 +949,7 @@ export function onDemandEntryHandler({
if (!bufferedHmrServerError && error) {
client.send(
JSON.stringify({
event: 'server-error', // for pages dir
action: 'serverError', // for app dir
action: 'serverError',
errorJSON: stringifyError(error),
})
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment