Skip to content

Commit

Permalink
remove unneeded error (#16636)
Browse files Browse the repository at this point in the history
This is not needed anymore since absolute urls are supported.
Also added an extra test for `mailto:` urls
  • Loading branch information
Janpot authored Aug 28, 2020
1 parent 5bda90f commit 20a4928
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
25 changes: 2 additions & 23 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,6 @@ function prepareUrlAs(router: NextRouter, url: Url, as: Url) {
}
}

function tryParseRelativeUrl(
url: string
): null | ReturnType<typeof parseRelativeUrl> {
try {
return parseRelativeUrl(url)
} catch (err) {
if (process.env.NODE_ENV !== 'production') {
setTimeout(() => {
throw new Error(
`Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed`
)
}, 0)
}
return null
}
}

export type BaseRouter = {
route: string
pathname: string
Expand Down Expand Up @@ -503,9 +486,7 @@ export default class Router implements BaseRouter {
const pages = await this.pageLoader.getPageList()
const { __rewrites: rewrites } = await this.pageLoader.promisedBuildManifest

let parsed = tryParseRelativeUrl(url)

if (!parsed) return false
let parsed = parseRelativeUrl(url)

let { pathname, searchParams } = parsed

Expand Down Expand Up @@ -899,9 +880,7 @@ export default class Router implements BaseRouter {
asPath: string = url,
options: PrefetchOptions = {}
): Promise<void> {
let parsed = tryParseRelativeUrl(url)

if (!parsed) return
let parsed = parseRelativeUrl(url)

let { pathname } = parsed

Expand Down
6 changes: 6 additions & 0 deletions test/integration/invalid-href/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ describe('Invalid hrefs', () => {
const $ = cheerio.load(await res.text())
expect($('#click-me').attr('href')).toBe('https://')
})

it('renders a link with mailto: href', async () => {
const res = await fetchViaHTTP(appPort, '/first')
const $ = cheerio.load(await res.text())
expect($('#click-me').attr('href')).toBe('mailto:[email protected]')
})
})

describe('dev mode', () => {
Expand Down

0 comments on commit 20a4928

Please sign in to comment.