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