mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Closes [#66650](https://github.com/vercel/next.js/issues/66650) Closes NEXT-3520 ### What? - Make Link not throw during prefetch if it received an invalid `href` (see [#66650](https://github.com/vercel/next.js/issues/66650)) - Throw in dev mode if an invalid link was passed to `router.prefetch` -- this matches current prod behavior - (previously, we'd immediately exit out of `router.prefetch`, so the user would see no indication that this'd fail in prod) ### Why? If an invalid URL was passed to `<Link>`, the whole app would crash and show "A client-side exception occurred". A failed prefetch should not bring down the whole app. Note that This preserves the current behavior of explicit `router.prefetch(url)` throwing an error if `url` is invalid. We may want to adjust this in the future, but that could be considered a breaking change, so I'm leaving it out for now. This only affects `Link`, which was intended to catch any errors thrown from `router.prefetch`, but that bit was accidentally broken.
9 lines
323 B
JavaScript
9 lines
323 B
JavaScript
// We need a URL that reliably fails `new URL(url, window.location)
|
|
// This only fails if `window.location` starts with `https://`:
|
|
//
|
|
// const invalidUrl = 'http:'
|
|
//
|
|
// because `new URL('http:', 'http://localhost:3000')` works fine.
|
|
// So better to pick something that's always invalid
|
|
export const INVALID_URL = '///'
|