Packages

@clerk/react-router

3.7.6 · 19 Nov 2026MIT138.1k / weekRepositoryHomepagenpmAtom feed

Your version

3.0.0

major3 Mar 2026Where it was published

3.7.8 is the newest release of 3.x.

In short

8 breaking1 removed6 new2 fixed3 internal

  • Breaking

    useAuth().getToken is no longer undefined during server-side rendering, it is a function and calling it will throw.

  • Breaking

    Refactor React SDK hooks to subscribe to auth state via useSyncExternalStore. This is a mostly internal refactor to unlock future improvements, but includes a few breaking changes and fixes.

  • Breaking

    Usage of rootAuthLoader without the clerkMiddleware() installed will not throw a runtime error.

  • Breaking

    Remove clerkJSUrl, clerkJSVersion, clerkUIUrl, and clerkUIVersion props from all SDKs. To pin a specific version of @clerk/clerk-js, import the Clerk constructor from @clerk/clerk-js and pass it to ClerkProvider via the Clerk prop. To pin a specific version of @clerk/ui, import ui from @clerk/ui and pass it via the ui prop. This bundles the modules directly with your application instead of loading them from the CDN.

  • Breaking

    Remove all previously deprecated UI props across the Next.js, React and clerk-js SDKs. The legacy afterSign(In|Up)Url/redirectUrl props, UserButton sign-out overrides, organization hideSlug flags, OrganizationSwitcher's afterSwitchOrganizationUrl, Client.activeSessions, setActive({ beforeEmit }), and the ClerkMiddlewareAuthObject type alias are no longer exported. Components now rely solely on the new redirect options and server-side configuration.

  • Breaking

    Remove @clerk/react-router/api.server export (use @clerk/react-router/server instead). Added codemod to automatically migrate.

  • Breaking

    Introduce <Show when={...}> as the cross-framework authorization control component and remove <Protect>, <SignedIn>, and <SignedOut> in favor of <Show>.

  • Breaking

    getToken() now throws ClerkOfflineError instead of returning null when the client is offline.

Security

1 advisory affects 3.0.0; 3.1.4 fixes them

Release note

Major Changes

  • Breaking

    useAuth().getToken is no longer undefined during server-side rendering, it is a function and calling it will throw.

    • If you are only using getToken in useEffect, event handlers or with non-suspenseful data fetching libraries, no change is necessary as these only trigger on the client.

    • If you are using suspenseful data fetching libraries that do trigger during SSR, you likely have strategies in place to avoid calling getToken already, since this has never been possible.

    • If you are using getToken === undefined checks to avoid calling it, know that it will now throw instead and you should catch and handle the error.

    async function doThingWithToken(getToken: GetToken) {
      try {
        const token = await getToken();
    
        // Use token
      } catch (error) {
        if (isClerkRuntimeError(error) && error.code === 'clerk_runtime_not_browser') {
          // Handle error
        }
      }
    }

    To access auth data server-side, see the Auth object reference doc.

  • Breaking

    Refactor React SDK hooks to subscribe to auth state via useSyncExternalStore. This is a mostly internal refactor to unlock future improvements, but includes a few breaking changes and fixes.

    Breaking changes:

    • Removes ability to pass in initialAuthState to useAuth

      • This was added for internal use and is no longer needed

      • Instead pass in initialState to the <ClerkProvider>, or dynamic if using the Next package

      • See your specific SDK documentation for more information on Server Rendering

    Fixes:

    • A bug where useAuth would sometimes briefly return the initialState rather than undefined

      • This could in certain situations incorrectly lead to a brief user: null on the first page after signing in, indicating a signed out state

    • Hydration mismatches in certain rare scenarios where subtrees would suspend and hydrate only after clerk-js had loaded fully

  • Breaking

    Usage of rootAuthLoader without the clerkMiddleware() installed will not throw a runtime error.

    Before (Removed):

    import { rootAuthLoader } from '@clerk/react-router/ssr.server';
    
    export const loader = (args: Route.LoaderArgs) => rootAuthLoader(args);

    After:

    1. Enable the v8_middleware future flag:

    // react-router.config.ts
    export default {
      future: {
        v8_middleware: true,
      },
    } satisfies Config;
    1. Use the middleware in your app:

    import { clerkMiddleware, rootAuthLoader } from '@clerk/react-router/server';
    
    export const middleware: Route.MiddlewareFunction[] = [clerkMiddleware()];
    
    export const loader = (args: Route.LoaderArgs) => rootAuthLoader(args);
  • Breaking

    Remove clerkJSUrl, clerkJSVersion, clerkUIUrl, and clerkUIVersion props from all SDKs. To pin a specific version of @clerk/clerk-js, import the Clerk constructor from @clerk/clerk-js and pass it to ClerkProvider via the Clerk prop. To pin a specific version of @clerk/ui, import ui from @clerk/ui and pass it via the ui prop. This bundles the modules directly with your application instead of loading them from the CDN.

  • Breaking

    Remove all previously deprecated UI props across the Next.js, React and clerk-js SDKs. The legacy afterSign(In|Up)Url/redirectUrl props, UserButton sign-out overrides, organization hideSlug flags, OrganizationSwitcher's afterSwitchOrganizationUrl, Client.activeSessions, setActive({ beforeEmit }), and the ClerkMiddlewareAuthObject type alias are no longer exported. Components now rely solely on the new redirect options and server-side configuration.

  • Breaking

    Remove @clerk/react-router/api.server export (use @clerk/react-router/server instead). Added codemod to automatically migrate.

  • Breaking

    Introduce <Show when={...}> as the cross-framework authorization control component and remove <Protect>, <SignedIn>, and <SignedOut> in favor of <Show>.

  • Breaking

    getToken() now throws ClerkOfflineError instead of returning null when the client is offline.

    This makes it explicit that a token fetch failure was due to network conditions, not authentication state. Previously, returning null could be misinterpreted as "user is signed out," potentially causing the cached token to be cleared.

    To handle this change, catch ClerkOfflineError from getToken() calls:

    import { ClerkOfflineError } from '@clerk/react/errors';
    
    try {
      const token = await session.getToken();
    } catch (error) {
      if (ClerkOfflineError.is(error)) {
        // Handle offline scenario - show offline UI, retry later, etc.
      }
      throw error;
    }

Minor Changes

  • Introduce Keyless quickstart for React Router. This allows the Clerk SDK to be used without having to sign up and paste your keys manually.

  • Introducing setup_mfa session task

  • Removed

    Remove clerkJSVariant option and headless bundle. Use prefetchUI={false} instead.

  • Add standalone getToken() function for retrieving session tokens outside of framework component trees.

    This function is safe to call from anywhere in the browser, such as API interceptors, data fetching layers (e.g., React Query, SWR), or vanilla JavaScript code. It automatically waits for Clerk to initialize before returning the token.

    import { getToken } from '@clerk/nextjs'; // or any framework package

    // Example: Axios interceptor
    axios.interceptors.request.use(async (config) => {
    const token = await getToken();
    if (token) {
    config.headers.Authorization = Bearer ${token};
    }
    return config;
    });

  • Export useOrganizationCreationDefaults hook to fetch suggested organization name and logo from default naming rules

  • Add /types subpath export to re-export types from @clerk/shared/types along with SDK-specific types. This allows importing Clerk types directly from the SDK package (e.g., import type { UserResource } from '@clerk/react/types') without needing to install @clerk/types as a separate dependency.

  • Introduce <UNSAFE_PortalProvider> component which allows you to specify a custom container for Clerk floating UI elements (popovers, modals, tooltips, etc.) that use portals. Only Clerk components within the provider will be affected, components outside the provider will continue to use the default document.body for portals.

    This is particularly useful when using Clerk components inside external UI libraries like Radix Dialog or React Aria Components, where portaled elements need to render within the dialog's container to remain interact-able.

    'use client';
    
    import { useRef } from 'react';
    import * as Dialog from '@radix-ui/react-dialog';
    import { UNSAFE_PortalProvider, UserButton } from '@clerk/nextjs';
    
    export function UserDialog() {
      const containerRef = useRef<HTMLDivElement>(null);
    
      return (
        <Dialog.Root>
          <Dialog.Trigger>Open Dialog</Dialog.Trigger>
          <Dialog.Portal>
            <Dialog.Overlay />
            <Dialog.Content ref={containerRef}>
              <UNSAFE_PortalProvider getContainer={() => containerRef.current}>
                <UserButton />
              </UNSAFE_PortalProvider>
            </Dialog.Content>
          </Dialog.Portal>
        </Dialog.Root>
      );
    }

Patch Changes

  • Wire clerkUIVersion option through all framework packages

  • Use new @clerk/react package.

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.