Add a .catch to shared router for ssg fetching. (#47265)

**Description:**
I noticed that when a user is on a deployed next.js site, and a fresh
deployment is made, requests for ssg data fails w/ a 404. For prefetches
(hovering a link) this appears to be handled well, but when the user
actually clicks the link it wasn't being handled.

This doesn't seem to be a problem as the page still behaves as expected,
but the errors being generated are clogging sentry.

To fix this, I added a simple `.catch(() => false)` as the return value
didn't appear to be used at all.

I was able to verify that this works correctly by patching next in a
local project and deploying a few times then clicking around.

**Issues**
As far as I know there's no issue tracking this atm as I chatted w/ Tim
in slack and he was under the impression that all of the failures were
caught.

Console on page navigation before this change:
<img width="775" alt="image"
src="https://user-images.githubusercontent.com/4172067/226069042-afa3a23b-b575-4e81-8ec4-ac887e38444d.png">

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
This commit is contained in:
Gary Borton 2023-03-20 13:19:25 -07:00 committed by GitHub
parent 7696124a5e
commit 47ac5d5f8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2432,7 +2432,9 @@ export default class Router implements BaseRouter {
options.unstable_skipClientCache ||
(options.priority &&
!!process.env.__NEXT_OPTIMISTIC_CLIENT_CACHE),
}).then(() => false)
})
.then(() => false)
.catch(() => false)
: false
}),
this.pageLoader[options.priority ? 'loadPage' : 'prefetch'](route),