Unverified Commit 0e29a2d0 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

reload the page to show 404 when receiving `invalid` event from on-demand-entries (#29074)

parent 07fe406b
......@@ -33,13 +33,24 @@ export function setupPing(assetPrefix, pathnameFn, retry) {
// the dev overlay as this can cause the error to be triggered
// repeatedly
if (payload.invalid && !self.__NEXT_DATA__.err) {
// Payload can be invalid even if the page does not exist.
// So, we need to make sure it exists before reloading.
// Payload can be invalid even if the page does exist.
// So, we check if it can be created.
fetch(location.href, {
credentials: 'same-origin',
}).then((pageRes) => {
if (pageRes.status === 200) {
// Page exists now, reload
location.reload()
} else {
// Page doesn't exist
if (
self.__NEXT_DATA__.page === currentPage &&
currentPage !== '/_error'
) {
// We are still on the page,
// reload to show 404 error page
location.reload()
}
}
})
}
......
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