diff --git a/.changeset/quiet-ladybugs-reply.md b/.changeset/quiet-ladybugs-reply.md new file mode 100644 index 00000000000..d0bea726560 --- /dev/null +++ b/.changeset/quiet-ladybugs-reply.md @@ -0,0 +1,5 @@ +--- +'@clerk/nextjs': patch +--- + +Fix shallow internal-component navigation. diff --git a/packages/nextjs/src/app-router/client/ClerkProvider.tsx b/packages/nextjs/src/app-router/client/ClerkProvider.tsx index b9a9cac154d..c12109385ca 100644 --- a/packages/nextjs/src/app-router/client/ClerkProvider.tsx +++ b/packages/nextjs/src/app-router/client/ClerkProvider.tsx @@ -98,7 +98,9 @@ const NextClientClerkProvider = (props: NextClerkProviderProps) => { const mergedProps = mergeNextClerkPropsWithEnv({ ...props, + // @ts-expect-error Error because of the stricter types of internal `push` routerPush: push, + // @ts-expect-error Error because of the stricter types of internal `replace` routerReplace: replace, }); diff --git a/packages/nextjs/src/app-router/client/useInternalNavFun.ts b/packages/nextjs/src/app-router/client/useInternalNavFun.ts index e1731b58fb0..780b335facc 100644 --- a/packages/nextjs/src/app-router/client/useInternalNavFun.ts +++ b/packages/nextjs/src/app-router/client/useInternalNavFun.ts @@ -15,7 +15,7 @@ export const useInternalNavFun = (props: { windowNav: typeof window.history.pushState | typeof window.history.replaceState | undefined; routerNav: AppRouterInstance['push'] | AppRouterInstance['replace']; name: string; -}) => { +}): NavigationFunction => { const { windowNav, routerNav, name } = props; const pathname = usePathname(); const [isPending, startTransition] = useTransition(); @@ -68,8 +68,8 @@ export const useInternalNavFun = (props: { } }, [pathname, isPending]); - return useCallback((to: string) => { - return getClerkNavigationObject(name).fun(to); + return useCallback((to, metadata) => { + return getClerkNavigationObject(name).fun(to, metadata); // We are not expecting name to change // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/packages/nextjs/src/global.d.ts b/packages/nextjs/src/global.d.ts index e9672e5b939..8757bee7f05 100644 --- a/packages/nextjs/src/global.d.ts +++ b/packages/nextjs/src/global.d.ts @@ -14,14 +14,24 @@ declare namespace NodeJS { } } -// eslint-disable-next-line @typescript-eslint/consistent-type-imports -type NextClerkProviderProps = import('./types').NextClerkProviderProps; +type RequireMetadata any> = T extends ( + to: infer To, + metadata?: infer Metadata, +) => infer R + ? (to: To, metadata: Metadata) => R + : never; + +type NavigationFunction = + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + | RequireMetadata> + // eslint-disable-next-line @typescript-eslint/consistent-type-imports + | RequireMetadata>; interface Window { __clerk_internal_navigations: Record< string, { - fun: NonNullable; + fun: NavigationFunction; promisesBuffer: Array<() => void> | undefined; } >; diff --git a/packages/types/src/snapshots.ts b/packages/types/src/snapshots.ts index e32ff390912..78c5715c21e 100644 --- a/packages/types/src/snapshots.ts +++ b/packages/types/src/snapshots.ts @@ -30,9 +30,7 @@ import type { import type { OrganizationSettingsJSON } from './organizationSettings'; import type { SignInJSON } from './signIn'; import type { UserSettingsJSON } from './userSettings'; -import type { Nullable } from './utils'; - -type Override = Omit & U; +import type { Nullable, Override } from './utils'; export type SignInJSONSnapshot = Override< Nullable, diff --git a/packages/types/src/utils.ts b/packages/types/src/utils.ts index 88227403440..861df403ae5 100644 --- a/packages/types/src/utils.ts +++ b/packages/types/src/utils.ts @@ -100,3 +100,11 @@ export type Autocomplete = U | (T & Record = { [P in keyof T as Exclude]: T[P]; }; + +/** + * Overrides the type of existing properties + * const obj = { a: string, b: number } as const; + * type Value = Override + * Value contains: { a:string, b: string } + */ +export type Override = Omit & U;