fix: handle 404 errors in HotReload client (#51637)
### What? In dev mode, routing to a 404 page will result in an infinite redirect cycle. This PR is an attempt to bring back similar functionality currently implemented in the [pages router.](https://github.com/vercel/next.js/blob/canary/packages/next/src/client/dev/on-demand-entries-client.ts#L41-L59) ### Why? When the `pong` event (emitted from `onHMR`) occurs on a page that doesn't exist, it will result in frequent calls to `router.fastRefresh()`. Because the server response is an error, it'll trigger a mpa navigation [here](https://github.com/vercel/next.js/blob/61ab4aadecb1f553fcb42ff9055d5b7af63c3f02/packages/next/src/client/components/router-reducer/fetch-server-response.ts#L115-L117), which is treated as an external route [here](https://github.com/vercel/next.js/blob/61ab4aadecb1f553fcb42ff9055d5b7af63c3f02/packages/next/src/client/components/router-reducer/reducers/fast-refresh-reducer.ts#L45-L53) (and thus the window is reloaded) In the case where you're on the page and it goes away, since we don't have access to `__NEXT_DATA__`, I opted to use the dispatcher which will trigger the parent `NotFoundBoundary`. This part felt a little awkward -- I'm open to suggestions on a better way to handle this. Closes NEXT-1299 Fixes #50585 --------- Co-authored-by:JJ Kasper <jj@jjsweb.site>
Showing
Please
register
or
sign in
to comment