Commit 71ae456a authored by JJ Kasper's avatar JJ Kasper Committed by Tim Neutkens

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

parent e0896e5d
......@@ -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)
......
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