Skip to content

fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057

Merged
jacekradko merged 7 commits into
mainfrom
jacek/path-matcher-path-star
Jul 6, 2026
Merged

fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types#9057
jacekradko merged 7 commits into
mainfrom
jacek/path-matcher-path-star

Conversation

@jacekradko

@jacekradko jacekradko commented Jul 1, 2026

Copy link
Copy Markdown
Member

createRouteMatcher's route-type suggestions now offer /dashboard/:path* instead of /dashboard(.*). (.*) also matches sibling routes like /dashboardxyz; :path* matches only /dashboard and its path-segment subtree. It's a type-level suggestion only (the param is Autocomplete-wrapped), so existing (.*) patterns keep type-checking and there's no runtime change.

The suggestion lives in a new WithPathSegmentWildcard type; the published WithPathPatternWildcard alias keeps its (.*) shape (now deprecated) so direct importers of @clerk/shared/pathMatcher don't break on a patch. break-check flagged an earlier in-place rewrite of that alias as a major for exactly that reason.

Worth a look: the root special-case. WithPathSegmentWildcard<'/'> resolves to /:path*, not the naive //:path* (which matches only / at runtime, not everything). I verified /dashboard/:path*, /:path*, and legacy (.*) against the vendored matcher, and @clerk/nextjs typechecks clean against it.

Scoped to the types on purpose: the ['/foo', '/bar(.*)'] JSDoc examples in nextjs/astro/nuxt are left as-is here and can be aligned in a follow-up. The docs are moving to recommend :path* too.

Summary by CodeRabbit

  • New Features
    • Route autocomplete suggestions now prefer the segment-aware :path* subtree wildcard syntax (e.g. /dashboard/:path*) for more accurate nested-path suggestions.
    • The legacy (.*) wildcard form is still supported, but the newer suggestion style is favored.
  • Bug Fixes
    • Improved autocomplete suggestion shapes for root paths and trailing slashes.
    • Changes affect type-level autocomplete output only; runtime route matching behavior is unchanged.

…ypes

WithPathPatternWildcard now suggests `/dashboard/:path*` instead of `/dashboard(.*)`.
The `:path*` form matches on path-segment boundaries, so it covers `/dashboard` and its
subtree without also matching sibling routes like `/dashboardxyz`. Root is special-cased
to `/:path*` to avoid a malformed `//:path*`. Backward compatible: the param is
Autocomplete-wrapped, so existing `(.*)` patterns still type-check, and there is no runtime change.
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 19186b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@clerk/shared Patch
@clerk/nextjs Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/electron Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/headless Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/react Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch
@clerk/swingset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Jul 6, 2026 3:32am
swingset Ready Ready Preview, Comment Jul 6, 2026 3:32am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 298296ce-8909-411f-bda6-6ea62dea2320

📥 Commits

Reviewing files that changed from the base of the PR and between 42aee20 and 19186b4.

📒 Files selected for processing (1)
  • .github/workflows/api-changes.yml

📝 Walkthrough

Walkthrough

This PR updates route-pattern autocomplete types to prefer :path*, switches the shared and Next.js matcher typings to the new wildcard shape, documents the change in a changeset, and bumps the break-check workflow to version 0.6.0.

Changes

Path wildcard type change

Layer / File(s) Summary
Shared wildcard types
packages/shared/src/pathMatcher.ts
WithPathSegmentWildcard is added, WithPathPatternWildcard is marked deprecated, and PathPattern now uses the new autocomplete source.
Route matcher typing and changeset
packages/nextjs/src/server/routeMatcher.ts, .changeset/path-matcher-segment-wildcard.md
The Next.js route matcher type uses the new shared wildcard type, and the changeset records the updated autocomplete suggestion behavior.

Break-check workflow version bump

Layer / File(s) Summary
Workflow version updates
.github/workflows/api-changes.yml
The baseline snapshot command and the pull request break-check step are both updated to version 0.6.0.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit hopped through routey code,
To :path* the suggestions flowed.
Old (.*) still keeps its place,
While workflows march at the right pace.
🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching route type suggestions to the :path* subtree form in shared and nextjs path matchers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@9057

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@9057

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@9057

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@9057

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@9057

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@9057

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@9057

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@9057

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@9057

@clerk/express

npm i https://pkg.pr.new/@clerk/express@9057

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@9057

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@9057

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@9057

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@9057

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@9057

@clerk/react

npm i https://pkg.pr.new/@clerk/react@9057

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@9057

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@9057

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@9057

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@9057

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@9057

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@9057

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@9057

commit: 19186b4

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

API Changes Report

Generated by Break Check on 2026-07-06T03:33:06.123Z

Summary

Metric Count
Packages analyzed 19
Packages with changes 1
🔴 Breaking changes 0
🟡 Non-breaking changes 1
🟢 Additions 1

🤖 This report was reviewed by claude-sonnet-4-6.


@clerk/shared

Current version: 4.23.0
Recommended bump: MINOR → 4.24.0

Subpath ./pathMatcher

🟡 Non-breaking Changes (1)

Modified: PathPattern
- type PathPattern = Autocomplete<WithPathPatternWildcard>;
+ type PathPattern = Autocomplete<WithPathSegmentWildcard>;

Static analyzer: Breaking change in type alias PathPattern: Type changed: import("@clerk/shared").~Autocomplete<import("@clerk/shared").WithPathPatternWildcard>import("@clerk/shared").~Autocomplete<import("@clerk/shared").WithPathSegmentWildcard>

🔤 Suggestion-only union change: the union keeps its Record<never,never>&string arm, which absorbs every string; the changed arms (removed: WithPathPatternWildcard; added: WithPathSegmentWildcard) only affect editor autocomplete, so no well-typed consumer is affected. Set downgradeAbsorbingArmUnions: false to keep these breaking.

🤖 AI review (confirmed) (97%): The absorbingArmUnion flag confirms that Autocomplete<WithPathPatternWildcard> and Autocomplete<WithPathSegmentWildcard> both resolve to a union containing the absorbing arm string & Record<never,never>, which accepts every string value; swapping the literal/template-literal suggestion arm (WithPathPatternWildcardWithPathSegmentWildcard) only affects autocomplete hints, not the assignable set.

🟢 Additions (1)

Added: WithPathSegmentWildcard
+ type WithPathSegmentWildcard<T = string> = T extends '/' ? '/:path*' : `${StripTrailingSlash<T & string>}/:path*`;

Added type alias WithPathSegmentWildcard


Report generated by Break Check

Last ran on 19186b4.

@jacekradko jacekradko changed the title fix(shared): suggest :path* subtree form in createRouteMatcher path types fix(shared,nextjs): suggest :path* subtree form in createRouteMatcher path types Jul 2, 2026
@github-actions github-actions Bot added the nextjs label Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/shared/src/pathMatcher.ts (1)

11-11: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Trailing-slash input produces a malformed double-slash suggestion.

For T = '/dashboard/', the non-root branch yields '/dashboard//:path*'. Root is special-cased but trailing slashes on other paths aren't, so the autocomplete suggestion could look malformed for such inputs. This is type-level only (no runtime impact via Autocomplete), but worth a quick look given the root case was already special-cased for the same class of problem.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/shared/src/pathMatcher.ts` at line 11, The WithPathSegmentWildcard
type in pathMatcher.ts only special-cases the root path, so trailing-slash
inputs like a non-root path ending in "/" can produce a malformed double-slash
suggestion. Update the type-level logic in WithPathSegmentWildcard to normalize
or strip a trailing slash before appending "/:path*", while preserving the
existing root-path special case. Keep the change confined to the path-matching
type aliases so Autocomplete continues to infer clean suggestions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/shared/src/pathMatcher.ts`:
- Around line 9-11: Add JSDoc to the public type WithPathSegmentWildcard in
pathMatcher so it is documented like the deprecated WithPathPatternWildcard and
included correctly in generated Clerk Docs. Replace the existing line comment
with a proper JSDoc block on the type alias, preserving the explanation about
the :path* subtree form and the special-case for '/'.

---

Nitpick comments:
In `@packages/shared/src/pathMatcher.ts`:
- Line 11: The WithPathSegmentWildcard type in pathMatcher.ts only special-cases
the root path, so trailing-slash inputs like a non-root path ending in "/" can
produce a malformed double-slash suggestion. Update the type-level logic in
WithPathSegmentWildcard to normalize or strip a trailing slash before appending
"/:path*", while preserving the existing root-path special case. Keep the change
confined to the path-matching type aliases so Autocomplete continues to infer
clean suggestions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Repository UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ba2b7da-063e-4f9d-9681-bec17ba96bb4

📥 Commits

Reviewing files that changed from the base of the PR and between 42cecb9 and 53a83be.

📒 Files selected for processing (3)
  • .changeset/path-matcher-segment-wildcard.md
  • packages/nextjs/src/server/routeMatcher.ts
  • packages/shared/src/pathMatcher.ts
✅ Files skipped from review due to trivial changes (1)
  • .changeset/path-matcher-segment-wildcard.md

Comment thread packages/shared/src/pathMatcher.ts Outdated
0.6.0 deterministically downgrades suggestion-only absorbing-arm union
changes (the Autocomplete / `string & Record<never, never>` idiom): a
union whose absorbing arm accepts every string is unchanged, so swapping
its literal arms only moves editor autocomplete. Without this, the
PathPattern change in this PR (`(.*)` to `:path*`) was flagged a
phantom breaking change. Bumps the action ref, the break-check-version
input, and the publish-baseline snapshot command.
@jacekradko jacekradko merged commit 2e1fec7 into main Jul 6, 2026
53 checks passed
@jacekradko jacekradko deleted the jacek/path-matcher-path-star branch July 6, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants