Skip to content

Commit 53a83be

Browse files
author
Jacek
committed
fix(shared): keep WithPathPatternWildcard intact, add WithPathSegmentWildcard
1 parent 42cecb9 commit 53a83be

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
'@clerk/shared': patch
3+
'@clerk/nextjs': patch
34
---
45

5-
`createRouteMatcher()` route suggestions now use the `:path*` subtree form (e.g. `/dashboard/:path*`) instead of `(.*)`. Unlike `/dashboard(.*)`, which also matches sibling routes such as `/dashboardxyz`, `/dashboard/:path*` matches only `/dashboard` and its path-segment subtree. Existing `(.*)` patterns keep working; this only changes the type-level autocomplete suggestion.
6+
`createPathMatcher()` and `createRouteMatcher()` route suggestions now use the `:path*` subtree form (e.g. `/dashboard/:path*`) instead of `(.*)`. Unlike `/dashboard(.*)`, which also matches sibling routes such as `/dashboardxyz`, `/dashboard/:path*` matches only `/dashboard` and its path-segment subtree. The new suggestion type is exported as `WithPathSegmentWildcard`; the existing `WithPathPatternWildcard` type is unchanged (now deprecated), and `(.*)` patterns keep working. This only changes the type-level autocomplete suggestion.

‎packages/nextjs/src/server/routeMatcher.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createPathMatcher, type WithPathPatternWildcard } from '@clerk/shared/pathMatcher';
1+
import { createPathMatcher, type WithPathSegmentWildcard } from '@clerk/shared/pathMatcher';
22
import type { Autocomplete } from '@clerk/shared/types';
33
import type Link from 'next/link';
44
import type { NextRequest } from 'next/server';
55

66
type NextTypedRoute<T = Parameters<typeof Link>['0']['href']> = T extends string ? T : never;
7-
type RouteMatcherWithNextTypedRoutes = Autocomplete<WithPathPatternWildcard<NextTypedRoute> | NextTypedRoute>;
7+
type RouteMatcherWithNextTypedRoutes = Autocomplete<WithPathSegmentWildcard<NextTypedRoute> | NextTypedRoute>;
88

99
export type RouteMatcherParam =
1010
| Array<RegExp | RouteMatcherWithNextTypedRoutes>

‎packages/shared/src/pathMatcher.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { pathToRegexp } from './pathToRegexp';
22
import type { Autocomplete } from './types';
33

4+
/**
5+
* @deprecated Prefer {@link WithPathSegmentWildcard}; `(.*)` also matches sibling routes
6+
* (e.g. `/dashboard(.*)` matches `/dashboardxyz`).
7+
*/
8+
export type WithPathPatternWildcard<T = string> = `${T & string}(.*)`;
49
// Suggests the `:path*` subtree form (e.g. `/dashboard/:path*`), which matches on
510
// path-segment boundaries. `/` is special-cased to `/:path*` to avoid a malformed `//:path*`.
6-
export type WithPathPatternWildcard<T = string> = T extends '/' ? '/:path*' : `${T & string}/:path*`;
7-
export type PathPattern = Autocomplete<WithPathPatternWildcard>;
11+
export type WithPathSegmentWildcard<T = string> = T extends '/' ? '/:path*' : `${T & string}/:path*`;
12+
export type PathPattern = Autocomplete<WithPathSegmentWildcard>;
813
export type PathMatcherParam = Array<RegExp | PathPattern> | RegExp | PathPattern;
914

1015
export class MalformedURLError extends Error {

0 commit comments

Comments
 (0)