Unverified Commit 9c70ede1 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Remove unused getParams matcher cache (#100078)

`last` was never getting assigned, so there was never a cache hit.

Even if it was implemented correctly, the benefits are questionable as a
LRU of size 1 isn't awfully effective anyway.
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
parent cad19c28
import { import { getRouteMatcher } from '../../shared/lib/router/utils/route-matcher'
type RouteMatchFn,
getRouteMatcher,
} from '../../shared/lib/router/utils/route-matcher'
import { getRouteRegex } from '../../shared/lib/router/utils/route-regex' import { getRouteRegex } from '../../shared/lib/router/utils/route-regex'
// The last page and matcher that this function handled.
let last: {
page: string
matcher: RouteMatchFn
} | null = null
/** /**
* Gets the params for the provided page. * Gets the params for the provided page.
* @param page the page that contains dynamic path parameters * @param page the page that contains dynamic path parameters
...@@ -17,17 +8,7 @@ let last: { ...@@ -17,17 +8,7 @@ let last: {
* @returns the matches that were found, throws otherwise * @returns the matches that were found, throws otherwise
*/ */
export function getParams(page: string, pathname: string) { export function getParams(page: string, pathname: string) {
// Because this is often called on the output of `getStaticPaths` or similar const params = getRouteMatcher(getRouteRegex(page))(pathname)
// where the `page` here doesn't change, this will "remember" the last page
// it created the RegExp for. If it matches, it'll just re-use it.
let matcher: RouteMatchFn
if (last?.page === page) {
matcher = last.matcher
} else {
matcher = getRouteMatcher(getRouteRegex(page))
}
const params = matcher(pathname)
if (!params) { if (!params) {
throw new Error( throw new Error(
`The provided export path '${pathname}' doesn't match the '${page}' page.\nRead more: https://nextjs.org/docs/messages/export-path-mismatch` `The provided export path '${pathname}' doesn't match the '${page}' page.\nRead more: https://nextjs.org/docs/messages/export-path-mismatch`
......
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