@clerk/react-router
3.7.6 · 19 Nov 2026MIT138.1k / weekRepositoryHomepagenpmAtom feed
3.7.8 is the newest release of 3.x.
In short
8 breaking1 removed6 new2 fixed3 internal
- Breaking
useAuth().getTokenis no longerundefinedduring 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
rootAuthLoaderwithout theclerkMiddleware()installed will not throw a runtime error. - Breaking
Remove
clerkJSUrl,clerkJSVersion,clerkUIUrl, andclerkUIVersionprops from all SDKs. To pin a specific version of@clerk/clerk-js, import theClerkconstructor from@clerk/clerk-jsand pass it toClerkProvidervia theClerkprop. To pin a specific version of@clerk/ui, importuifrom@clerk/uiand pass it via theuiprop. 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/redirectUrlprops,UserButtonsign-out overrides, organizationhideSlugflags,OrganizationSwitcher'safterSwitchOrganizationUrl,Client.activeSessions,setActive({ beforeEmit }), and theClerkMiddlewareAuthObjecttype alias are no longer exported. Components now rely solely on the new redirect options and server-side configuration. - Breaking
Remove
@clerk/react-router/api.serverexport (use@clerk/react-router/serverinstead). 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 throwsClerkOfflineErrorinstead of returningnullwhen the client is offline.
Security
1 advisory affects 3.0.0; 3.1.4 fixes them
- HighClerk has an authorization bypass when combining organization, billing, or reverification checksGHSA-w24r-5266-9c3c · 30 Apr 2026Fixed in 3.1.4
Release note
Major Changes
- Breaking
useAuth().getTokenis no longerundefinedduring server-side rendering, it is a function and calling it will throw.If you are only using
getTokeninuseEffect, 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
getTokenalready, since this has never been possible.If you are using
getToken === undefinedchecks 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
Authobject 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
initialAuthStatetouseAuthThis was added for internal use and is no longer needed
Instead pass in
initialStateto the<ClerkProvider>, ordynamicif using the Next packageSee your specific SDK documentation for more information on Server Rendering
Fixes:
A bug where
useAuthwould sometimes briefly return theinitialStaterather thanundefinedThis could in certain situations incorrectly lead to a brief
user: nullon 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-jshad loaded fully
- Breaking
Usage of
rootAuthLoaderwithout theclerkMiddleware()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:
Enable the
v8_middlewarefuture flag:
// react-router.config.ts export default { future: { v8_middleware: true, }, } satisfies Config;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, andclerkUIVersionprops from all SDKs. To pin a specific version of@clerk/clerk-js, import theClerkconstructor from@clerk/clerk-jsand pass it toClerkProvidervia theClerkprop. To pin a specific version of@clerk/ui, importuifrom@clerk/uiand pass it via theuiprop. 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/redirectUrlprops,UserButtonsign-out overrides, organizationhideSlugflags,OrganizationSwitcher'safterSwitchOrganizationUrl,Client.activeSessions,setActive({ beforeEmit }), and theClerkMiddlewareAuthObjecttype alias are no longer exported. Components now rely solely on the new redirect options and server-side configuration. - Breaking
Remove
@clerk/react-router/api.serverexport (use@clerk/react-router/serverinstead). 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 throwsClerkOfflineErrorinstead of returningnullwhen the client is offline.This makes it explicit that a token fetch failure was due to network conditions, not authentication state. Previously, returning
nullcould be misinterpreted as "user is signed out," potentially causing the cached token to be cleared.To handle this change, catch
ClerkOfflineErrorfromgetToken()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_mfasession task- Removed
Remove
clerkJSVariantoption and headless bundle. UseprefetchUI={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
useOrganizationCreationDefaultshook to fetch suggested organization name and logo from default naming rulesAdd
/typessubpath export to re-export types from@clerk/shared/typesalong 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/typesas 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
clerkUIVersionoption through all framework packagesUse new
@clerk/reactpackage.
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.