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 }) => { ...@@ -34,18 +34,20 @@ export default async ({ assetPrefix }) => {
} }
evtSource.onmessage = event => { evtSource.onmessage = event => {
const payload = JSON.parse(event.data) try {
if (payload.invalid) { const payload = JSON.parse(event.data)
// Payload can be invalid even if the page does not exist. if (payload.invalid) {
// So, we need to make sure it exists before reloading. // Payload can be invalid even if the page does not exist.
fetch(location.href, { // So, we need to make sure it exists before reloading.
credentials: 'same-origin' fetch(location.href, {
}).then(pageRes => { credentials: 'same-origin'
if (pageRes.status === 200) { }).then(pageRes => {
location.reload() if (pageRes.status === 200) {
} location.reload()
}) }
} })
}
} catch (_) { /* noop */ }
} }
} }
......
...@@ -303,6 +303,7 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, { ...@@ -303,6 +303,7 @@ export default function onDemandEntryHandler (devMiddleware, multiCompiler, {
const runPing = () => { const runPing = () => {
const data = handlePing(query.page) const data = handlePing(query.page)
if (!data) return
res.write('data: ' + JSON.stringify(data) + '\n\n') res.write('data: ' + JSON.stringify(data) + '\n\n')
} }
const pingInterval = setInterval(() => runPing(), 5000) 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