Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/every-glasses-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/react-router': patch
---

In this release the TypeScript types for `rootAuthLoader()`, `getAuth()`, and `<ClerkProvider>` were adjusted but should still work as before. Previously, these types relied on internal, unstable React Router types that changed in their recent 7.6.1 release. We simplified our TypeScript types and no longer rely on internal exports from React Router.
2 changes: 1 addition & 1 deletion packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"devDependencies": {
"@types/cookie": "^0.6.0",
"esbuild-plugin-file-path-extensions": "^2.1.4",
"react-router": "7.5.2"
"react-router": "7.6.1"
},
"peerDependencies": {
"react": "catalog:peer-react",
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router/src/client/ReactRouterClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
warnForSsr,
} from '../utils/assert';
import { ClerkReactRouterOptionsProvider } from './ReactRouterOptionsContext';
import type { ClerkState, ReactRouterClerkProviderProps, ReactRouterComponentProps } from './types';
import type { ClerkState, ReactRouterClerkProviderProps } from './types';
import { useAwaitableNavigate } from './useAwaitableNavigate';

export * from '@clerk/clerk-react';
Expand Down Expand Up @@ -119,9 +119,9 @@ type ClerkReactRouterOptions = Partial<
Omit<ReactRouterClerkProviderProps, 'routerPush' | 'routerReplace' | 'clerkState'>
>;

// TODO: Remove "any" on loaderData type
// TODO: Remove "any" on loaderData type and use Route.ComponentProps from userland code
type ClerkProviderProps = ClerkReactRouterOptions & {
loaderData?: ReactRouterComponentProps['loaderData'];
loaderData?: any;
Copy link
Contributor Author

@LekoArts LekoArts Jun 3, 2025

Choose a reason for hiding this comment

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

This was already resolving to any previously, so we can remove the reliance on react-router/route-module here

};

export const ClerkProvider = ({ children, loaderData, ...opts }: ClerkProviderProps) => {
Expand Down
3 changes: 0 additions & 3 deletions packages/react-router/src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import type { ClerkProviderProps } from '@clerk/clerk-react';
import type { InitialState, Without } from '@clerk/types';
import type React from 'react';
import type { CreateComponentProps } from 'react-router/route-module';

export type ReactRouterComponentProps = CreateComponentProps<any>;

export type ClerkState = {
__type: 'clerkState';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/src/ssr/authenticateRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { createClerkClient } from '@clerk/backend';
import type { AuthenticateRequestOptions, SignedInState, SignedOutState } from '@clerk/backend/internal';
import { AuthStatus, constants } from '@clerk/backend/internal';
import { handleNetlifyCacheInDevInstance } from '@clerk/shared/netlifyCacheHandler';
import type { LoaderFunctionArgs } from 'react-router';

import type { LoaderFunctionArgs } from './types';
import { patchRequest } from './utils';

export async function authenticateRequest(
Expand Down
3 changes: 2 additions & 1 deletion packages/react-router/src/ssr/getAuth.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { stripPrivateDataFromObject } from '@clerk/backend/internal';
import type { LoaderFunctionArgs } from 'react-router';

import { noLoaderArgsPassedInGetAuth } from '../utils/errors';
import { authenticateRequest } from './authenticateRequest';
import { loadOptions } from './loadOptions';
import type { GetAuthReturn, LoaderFunctionArgs, RootAuthLoaderOptions } from './types';
import type { GetAuthReturn, RootAuthLoaderOptions } from './types';

type GetAuthOptions = Pick<RootAuthLoaderOptions, 'secretKey'>;

Expand Down
3 changes: 2 additions & 1 deletion packages/react-router/src/ssr/loadOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { getEnvVariable } from '@clerk/shared/getEnvVariable';
import { isDevelopmentFromSecretKey } from '@clerk/shared/keys';
import { isHttpOrHttps, isProxyUrlRelative } from '@clerk/shared/proxy';
import { handleValueOrFn } from '@clerk/shared/utils';
import type { LoaderFunctionArgs } from 'react-router';

import { getPublicEnvVariables } from '../utils/env';
import { noSecretKeyError, satelliteAndMissingProxyUrlAndDomain, satelliteAndMissingSignInUrl } from '../utils/errors';
import type { LoaderFunctionArgs, RootAuthLoaderOptions } from './types';
import type { RootAuthLoaderOptions } from './types';
import { patchRequest } from './utils';

export const loadOptions = (args: LoaderFunctionArgs, overrides: RootAuthLoaderOptions = {}) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-router/src/ssr/rootAuthLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { decorateObjectWithResources } from '@clerk/backend/internal';
import type { LoaderFunctionArgs } from 'react-router';

import { invalidRootLoaderCallbackReturn } from '../utils/errors';
import { authenticateRequest } from './authenticateRequest';
import { loadOptions } from './loadOptions';
import type { LoaderFunctionArgs, LoaderFunctionReturn, RootAuthLoaderCallback, RootAuthLoaderOptions } from './types';
import type { LoaderFunctionReturn, RootAuthLoaderCallback, RootAuthLoaderOptions } from './types';
import {
assertValidHandlerResult,
injectRequestStateIntoResponse,
Expand Down
32 changes: 1 addition & 31 deletions packages/react-router/src/ssr/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,7 @@ import type {
SignUpFallbackRedirectUrl,
SignUpForceRedirectUrl,
} from '@clerk/types';
import type { LoaderFunction, UNSAFE_DataWithResponseInit } from 'react-router';
import type { CreateServerLoaderArgs } from 'react-router/route-module';

type Func = (...args: any[]) => unknown;

type RouteModule = {
meta?: Func;
links?: Func;
headers?: Func;
loader?: Func;
clientLoader?: Func;
action?: Func;
clientAction?: Func;
HydrateFallback?: unknown;
default?: unknown;
ErrorBoundary?: unknown;
[key: string]: unknown;
};

export type RouteInfo = {
parents: RouteInfo[];
module: RouteModule;
id: unknown;
file: string;
path: string;
params: unknown;
loaderData: unknown;
actionData: unknown;
};
import type { LoaderFunction, LoaderFunctionArgs, UNSAFE_DataWithResponseInit } from 'react-router';

export type GetAuthReturn = Promise<SignedInAuthObject | SignedOutAuthObject>;

Expand Down Expand Up @@ -101,8 +73,6 @@ type RootAuthLoaderCallbackReturn =
| UNSAFE_DataWithResponseInit<unknown>
| Promise<UNSAFE_DataWithResponseInit<unknown>>;

// TODO: Figure out how to use the Route.LoaderArgs from userland code
export type LoaderFunctionArgs = CreateServerLoaderArgs<RouteInfo>;
export type LoaderFunctionReturn = ReturnType<LoaderFunction>;

export type LoaderFunctionArgsWithAuth<Options extends RootAuthLoaderOptions = any> = LoaderFunctionArgs & {
Expand Down
18 changes: 6 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.