Fix invalid ping response throwing error in client (#6397)

This commit is contained in:
JJ Kasper 2019-02-22 03:22:23 -06:00 committed by Tim Neutkens
parent e0896e5dbe
commit 71ae456a7c
2 changed files with 15 additions and 12 deletions

View file

@ -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 */ }
}
}

View file

@ -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)