Skip to content

Conversation

tunnckoCore
Copy link

@tunnckoCore tunnckoCore commented Oct 4, 2025

Description

The following tries to implement support for Tanstack Start/Router because currently error is thrown when @clerk/elements is used there.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Running tests crashed my machine so.. don't know,. But there's no other changes and there's no tests for that feeture specifically, so current tests should work ok. I'm just quick contributing, someone else could continue.

There's basically just 2 new files alongside the Nextjs ones, so nothign else is changed.

Summary by CodeRabbit

  • New Features

    • TanStack Router integration for Clerk Elements enabling SPA navigation.
    • Push, replace and shallow navigation methods without full page reloads.
    • Automatic base-path detection for consistent URLs.
    • Improved handling of optional catch-all routes for accurate path resolution.
    • Exposes current pathname and search parameters for UI components.
  • Chore

    • Added TanStack Router as a development dependency.

Copy link

changeset-bot bot commented Oct 4, 2025

⚠️ No Changeset found

Latest commit: a93c10c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link

vercel bot commented Oct 4, 2025

@tunnckoCore is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Adds TanStack Router integration and a pathname-inference hook for Clerk Elements: exports useTanStackRouter() adapter exposing navigation and URL state, and usePathnameWithoutCatchAll() which derives a normalized base path by stripping optional catch-all segments.

Changes

Cohort / File(s) Summary
TanStack Router integration
packages/elements/src/react/router/tanstack.ts
Adds useTanStackRouter() exported hook returning a ClerkHostRouter-like adapter: mode/name, push/replace/shallowPush implemented via TanStack Router navigation; exposes current pathname, searchParams, and inferredBasePath.
Path inference utility
packages/elements/src/react/utils/path-inference/tanstack.tsx
Adds usePathnameWithoutCatchAll() exported hook: reads location.pathname and params from TanStack Router, detects and strips optional catch-all segments, normalizes trailing slashes, and memoizes the result.
Dev dependency update
packages/elements/package.json
Adds devDependency @tanstack/react-router@1.131.49.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor UI as React Component
  participant Adapter as useTanStackRouter
  participant TR as TanStack Router

  UI->>Adapter: call useTanStackRouter()
  Adapter->>TR: access router, location (pathname, search), params
  Adapter-->>UI: returns { push, replace, shallowPush, pathname, searchParams, inferredBasePath }

  UI->>Adapter: push(url)
  Adapter->>TR: router.navigate({ to: url })

  UI->>Adapter: replace(url)
  Adapter->>TR: router.navigate({ to: url, replace: true })
Loading
sequenceDiagram
  autonumber
  actor UI as React Component
  participant Hook as usePathnameWithoutCatchAll
  participant TR as TanStack Router

  UI->>Hook: call usePathnameWithoutCatchAll()
  Hook->>TR: read router.location.pathname
  Hook->>TR: read route params (useParams)
  alt optional catch-all present
    Hook-->>UI: return pathname with catch-all segment removed (normalized)
  else
    Hook-->>UI: return normalized pathname
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my whiskers at each route,
I hop where paths and queries suit.
I nudge the stack, I trim the tail,
A tidy trail along the trail.
Hooray — new hops for every route! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title follows conventional commit style and concisely describes that support for TanStack is being added to the @clerk/elements package, which aligns directly with the addition of new hooks and dependency updates for TanStack Router. It clearly signals the primary feature change without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@tunnckoCore tunnckoCore changed the title feat: start support for tanstack feat: start support for tanstack in @clerk/elements Oct 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c6724e9 and ad67fac.

📒 Files selected for processing (2)
  • packages/elements/src/react/router/tanstack.ts (1 hunks)
  • packages/elements/src/react/utils/path-inference/tanstack.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/elements/src/react/router/tanstack.ts
  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components: UserProfile, NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
🧬 Code graph analysis (1)
packages/elements/src/react/router/tanstack.ts (1)
packages/elements/src/react/utils/path-inference/tanstack.tsx (1)
  • usePathnameWithoutCatchAll (16-53)
🪛 Biome (2.1.2)
packages/elements/src/react/utils/path-inference/tanstack.tsx

[error] 26-26: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

Hooks should not be called after an early return.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)


[error] 28-28: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

Hooks should not be called after an early return.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: semgrep-cloud-platform/scan

ok

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/elements/src/react/router/tanstack.ts (1)

28-30: Clarify the "shallow" navigation comment.

The comment states "all navigations are already shallow," but this doesn't clearly explain the difference between push and shallowPush, or why router.history.push is used here versus router.navigate in the push method above.

Consider revising the comment to be more explicit:

     shallowPush: (path: string) =>
-      // In TanStack Router, all navigations are already shallow; reuse the standard history push.
+      // Uses router.history.push to update the URL without triggering loaders or navigation guards.
+      // This preserves the current component state and only updates the browser history.
       router.history.push(path),
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ad67fac and 60e0cf0.

📒 Files selected for processing (1)
  • packages/elements/src/react/router/tanstack.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/elements/src/react/router/tanstack.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/elements/src/react/router/tanstack.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/elements/src/react/router/tanstack.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/elements/src/react/router/tanstack.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/elements/src/react/router/tanstack.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/elements/src/react/router/tanstack.ts
🧬 Code graph analysis (1)
packages/elements/src/react/router/tanstack.ts (1)
packages/elements/src/react/utils/path-inference/tanstack.tsx (1)
  • usePathnameWithoutCatchAll (16-53)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: semgrep-cloud-platform/scan

Signed-off-by: tunnckoCore <[email protected]>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (2)
packages/elements/src/react/utils/path-inference/tanstack.tsx (2)

39-39: Consider memoizing params to reduce recomputations.

useParams() from TanStack Router likely returns a new object reference on every render, causing the useMemo to recompute even when param values haven't changed. This is a performance consideration rather than a correctness issue.

If profiling shows performance concerns, you could add a second layer of memoization to stabilize the params reference:

 export const usePathnameWithoutCatchAll = (): string => {
   const router = useRouter();
 
   const pathname = router?.location.pathname || '';
   const params = useParams() as Record<string, string | string[] | undefined>;
+  
+  const stableParams = React.useMemo(
+    () => params,
+    [JSON.stringify(params)] // or use a deep-equality hook
+  );
 
   return React.useMemo(() => {
     const processedPath = removeOptionalCatchAllSegment(pathname);
     const pathParts = processedPath.split('/').filter(Boolean);
-    const catchAllParams = Object.values(params || {})
+    const catchAllParams = Object.values(stableParams || {})
       .filter((v): v is string[] => Array.isArray(v))
       .flat(Infinity);
 
     if (!pathname || catchAllParams.length === 0) {
       return pathname.replace(/\/$/, '') || '/';
     }
 
     const baseParts = pathParts.slice(0, pathParts.length - catchAllParams.length);
     const basePath = `/${baseParts.join('/')}`;
 
     return basePath.replace(/\/$/, '') || '/';
-  }, [pathname, params]);
+  }, [pathname, stableParams]);
 };

Alternatively, consider using a library like react-fast-compare or use-deep-compare-effect for stable deep-equality checks.


23-23: Drop or clarify redundant removeOptionalCatchAllSegment call
removeOptionalCatchAllSegment uses /\/\[\[\.\.\..*/ to strip optional catch-all syntax from route patterns, but when given an actual pathname it has no effect. Remove this call or rename the utility to reflect its intent.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 60e0cf0 and a93c10c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/elements/package.json (1 hunks)
  • packages/elements/src/react/router/tanstack.ts (1 hunks)
  • packages/elements/src/react/utils/path-inference/tanstack.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/elements/src/react/router/tanstack.ts
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
  • packages/elements/package.json
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{jsx,tsx}: Use error boundaries in React components
Minimize re-renders in React components

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components: UserProfile, NavigationMenu
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Use useState for simple state management
Use useReducer for complex state logic
Implement proper state initialization
Use proper state updates with callbacks
Implement proper state cleanup
Use Context API for theme/authentication
Implement proper state selectors
Use proper state normalization
Implement proper state persistence
Use React.memo for expensive components
Implement proper useCallback for handlers
Use proper useMemo for expensive computations
Implement proper virtualization for lists
Use proper code splitting with React.lazy
Implement proper cleanup in useEffect
Use proper refs for DOM access
Implement proper event listener cleanup
Use proper abort controllers for fetch
Implement proper subscription cleanup
Use proper HTML elements
Implement proper ARIA attributes
Use proper heading hierarchy
Implement proper form labels
Use proper button types
Implement proper focus management
Use proper keyboard shortcuts
Implement proper tab order
Use proper skip links
Implement proper focus traps
Implement proper error boundaries
Use proper error logging
Implement proper error recovery
Use proper error messages
Implement proper error fallbacks
Use proper form validation
Implement proper error states
Use proper error messages
Implement proper form submission
Use proper form reset
Use proper component naming
Implement proper file naming
Use proper prop naming
Implement proper...

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/react.mdc)

**/*.tsx: Use proper type definitions for props and state
Leverage TypeScript's type inference where possible
Use proper event types for handlers
Implement proper generic types for reusable components
Use proper type guards for conditional rendering

Files:

  • packages/elements/src/react/utils/path-inference/tanstack.tsx
packages/*/package.json

📄 CodeRabbit inference engine (.cursor/rules/global.mdc)

All publishable packages should be placed under the packages/ directory

packages/*/package.json: All publishable packages must be located in the 'packages/' directory.
All packages must be published under the @clerk namespace on npm.
Semantic versioning must be used across all packages.

Files:

  • packages/elements/package.json
🔇 Additional comments (1)
packages/elements/src/react/utils/path-inference/tanstack.tsx (1)

17-20: Hooks rule violation fixed—well done!

The previous review correctly flagged that hooks were called after an early return. The current implementation properly calls both useRouter() and useParams() at the top level before any conditional logic or returns. This ensures React's hooks rules are followed and prevents crashes when the router becomes available later.

},
"devDependencies": {
"@statelyai/inspect": "^0.4.0",
"@tanstack/react-router": "1.131.49",
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add TanStack Router as an optional peer dependency for consistency.

The package follows a pattern where framework-specific integrations (like Next.js) are listed as both devDependencies (for testing) and optional peerDependencies (for proper resolution in user projects). TanStack Router should follow the same pattern to ensure users can manage their own version while @clerk/elements adapts to it.

Apply this diff to add TanStack Router as an optional peer dependency:

   "peerDependencies": {
+    "@tanstack/react-router": "^1.0.0",
     "next": "^13.5.4 || ^14.0.3 || ^15",
     "react": "catalog:peer-react",
     "react-dom": "catalog:peer-react"
   },
   "peerDependenciesMeta": {
+    "@tanstack/react-router": {
+      "optional": true
+    },
     "next": {
       "optional": true
     }
   },
🤖 Prompt for AI Agents
In packages/elements/package.json around line 89, add "@tanstack/react-router":
"1.131.49" to the optionalPeerDependencies object (create the
optionalPeerDependencies section if it doesn't exist) so TanStack Router is
listed as an optional peer dependency for consumers; also ensure the same
version is present in devDependencies (add it there if missing) so tests/builds
use the pinned version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants