Fix invalid ping response throwing error in client (#6397)
This commit is contained in:
parent
e0896e5dbe
commit
71ae456a7c
2 changed files with 15 additions and 12 deletions
|
@ -34,18 +34,20 @@ export default async ({ assetPrefix }) => {
|
|||
}
|
||||
|
||||
evtSource.onmessage = event => {
|
||||
const payload = JSON.parse(event.data)
|
||||
if (payload.invalid) {
|
||||
// Payload can be invalid even if the page does not exist.
|
||||
// So, we need to make sure it exists before reloading.
|
||||
fetch(location.href, {
|
||||
credentials: 'same-origin'
|
||||
}).then(pageRes => {
|
||||
if (pageRes.status === 200) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
try {
|
||||
const payload = JSON.parse(event.data)
|
||||
if (payload.invalid) {
|
||||
// Payload can be invalid even if the page does not exist.
|
||||
// So, we need to make sure it exists before reloading.
|
||||
fetch(location.href, {
|
||||
credentials: 'same-origin'
|
||||
}).then(pageRes => {
|
||||
if (pageRes.status === 200) {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (_) { /* noop */ }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -303,6 +303,7 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
|
|||
|
||||
const runPing = () => {
|
||||
const data = handlePing(query.page)
|
||||
if (!data) return
|
||||
res.write('data: ' + JSON.stringify(data) + '\n\n')
|
||||
}
|
||||
const pingInterval = setInterval(() => runPing(), 5000)
|
||||
|
|
Loading…
Reference in a new issue