Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unneeded error #16636

Merged
merged 3 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:idk@idk.com')
})
})

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