Unverified Commit 764b1945 authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

make parseRelativeUrl return a UrlObject (#16809)

Alternative to https://github.com/vercel/next.js/pull/16798
parent 0e843e60
...@@ -12,7 +12,6 @@ import { ...@@ -12,7 +12,6 @@ import {
import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route' import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import { parseRelativeUrl } from '../next-server/lib/router/utils/parse-relative-url' import { parseRelativeUrl } from '../next-server/lib/router/utils/parse-relative-url'
import { searchParamsToUrlQuery } from '../next-server/lib/router/utils/querystring'
export const looseToArray = <T extends {}>(input: any): T[] => export const looseToArray = <T extends {}>(input: any): T[] =>
[].slice.call(input) [].slice.call(input)
...@@ -204,10 +203,7 @@ export default class PageLoader { ...@@ -204,10 +203,7 @@ export default class PageLoader {
* @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes * @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes
*/ */
getDataHref(href: string, asPath: string, ssg: boolean) { getDataHref(href: string, asPath: string, ssg: boolean) {
const { pathname: hrefPathname, searchParams, search } = parseRelativeUrl( const { pathname: hrefPathname, query, search } = parseRelativeUrl(href)
href
)
const query = searchParamsToUrlQuery(searchParams)
const { pathname: asPathname } = parseRelativeUrl(asPath) const { pathname: asPathname } = parseRelativeUrl(asPath)
const route = normalizeRoute(hrefPathname) const route = normalizeRoute(hrefPathname)
......
...@@ -563,7 +563,7 @@ export default class Router implements BaseRouter { ...@@ -563,7 +563,7 @@ export default class Router implements BaseRouter {
let parsed = parseRelativeUrl(url) let parsed = parseRelativeUrl(url)
let { pathname, searchParams } = parsed let { pathname, query } = parsed
parsed = this._resolveHref(parsed, pages) as typeof parsed parsed = this._resolveHref(parsed, pages) as typeof parsed
...@@ -572,8 +572,6 @@ export default class Router implements BaseRouter { ...@@ -572,8 +572,6 @@ export default class Router implements BaseRouter {
url = formatWithValidation(parsed) url = formatWithValidation(parsed)
} }
const query = searchParamsToUrlQuery(searchParams)
// url and as should always be prefixed with basePath by this // url and as should always be prefixed with basePath by this
// point by either next/link or router.push/replace so strip the // point by either next/link or router.push/replace so strip the
// basePath from the pathname to match the pages dir 1-to-1 // basePath from the pathname to match the pages dir 1-to-1
......
import { getLocationOrigin } from '../../utils' import { getLocationOrigin } from '../../utils'
import { searchParamsToUrlQuery } from './querystring'
const DUMMY_BASE = new URL( const DUMMY_BASE = new URL(
typeof window === 'undefined' ? 'http://n' : getLocationOrigin() typeof window === 'undefined' ? 'http://n' : getLocationOrigin()
...@@ -29,7 +30,7 @@ export function parseRelativeUrl(url: string, base?: string) { ...@@ -29,7 +30,7 @@ export function parseRelativeUrl(url: string, base?: string) {
} }
return { return {
pathname, pathname,
searchParams, query: searchParamsToUrlQuery(searchParams),
search, search,
hash, hash,
href: href.slice(DUMMY_BASE.origin.length), href: href.slice(DUMMY_BASE.origin.length),
......
...@@ -35,7 +35,7 @@ export default function prepareDestination( ...@@ -35,7 +35,7 @@ export default function prepareDestination(
parsedDestination = { parsedDestination = {
pathname, pathname,
searchParams, query: searchParamsToUrlQuery(searchParams),
hash, hash,
protocol, protocol,
hostname, hostname,
...@@ -45,9 +45,6 @@ export default function prepareDestination( ...@@ -45,9 +45,6 @@ export default function prepareDestination(
} }
} }
parsedDestination.query = searchParamsToUrlQuery(
parsedDestination.searchParams
)
const destQuery = parsedDestination.query const destQuery = parsedDestination.query
const destPath = `${parsedDestination.pathname!}${ const destPath = `${parsedDestination.pathname!}${
parsedDestination.hash || '' parsedDestination.hash || ''
...@@ -108,7 +105,6 @@ export default function prepareDestination( ...@@ -108,7 +105,6 @@ export default function prepareDestination(
parsedDestination.pathname = pathname parsedDestination.pathname = pathname
parsedDestination.hash = `${hash ? '#' : ''}${hash || ''}` parsedDestination.hash = `${hash ? '#' : ''}${hash || ''}`
delete parsedDestination.search delete parsedDestination.search
delete parsedDestination.searchParams
} catch (err) { } catch (err) {
if (err.message.match(/Expected .*? to not repeat, but got an array/)) { if (err.message.match(/Expected .*? to not repeat, but got an array/)) {
throw new Error( throw new Error(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment