From 950f4b2ead2892322bdce03532f1e77ea90ab4a0 Mon Sep 17 00:00:00 2001 From: George Desipris <73396808+desiprisg@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:37:40 +0200 Subject: [PATCH] chore(clerk-js): Apply changes to PathRouter for retheme directory (#2222) * chore(clerk-js): Apply changes to PathRouter for retheme directory * fix(types): Add NavigationOptions in retheme --------- Co-authored-by: Dimitris Klouvas --- .changeset/soft-swans-swim.md | 2 ++ packages/clerk-js/src/ui.retheme/router/PathRouter.tsx | 7 ++++--- packages/types/src/clerk.retheme.ts | 9 +++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/soft-swans-swim.md diff --git a/.changeset/soft-swans-swim.md b/.changeset/soft-swans-swim.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/soft-swans-swim.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/clerk-js/src/ui.retheme/router/PathRouter.tsx b/packages/clerk-js/src/ui.retheme/router/PathRouter.tsx index bbb951e035..c9211cd158 100644 --- a/packages/clerk-js/src/ui.retheme/router/PathRouter.tsx +++ b/packages/clerk-js/src/ui.retheme/router/PathRouter.tsx @@ -1,3 +1,4 @@ +import type { NavigateOptions } from '@clerk/types'; import React from 'react'; import { hasUrlInFragment, mergeFragmentIntoUrl, stripOrigin } from '../../utils'; @@ -18,12 +19,12 @@ export const PathRouter = ({ basePath, preservedParams, children }: PathRouterPr throw new Error('Clerk: Missing navigate option.'); } - const internalNavigate = (toURL: URL | string | undefined) => { + const internalNavigate = (toURL: URL | string | undefined, options?: NavigateOptions) => { if (!toURL) { return; } // Only send the path - return navigate(stripOrigin(toURL)); + return navigate(stripOrigin(toURL), options); }; const getPath = () => { @@ -38,7 +39,7 @@ export const PathRouter = ({ basePath, preservedParams, children }: PathRouterPr const convertHashToPath = async () => { if (hasUrlInFragment(window.location.hash)) { const url = mergeFragmentIntoUrl(new URL(window.location.href)); - await internalNavigate(url.href); + await internalNavigate(url.href, { replace: true }); setStripped(true); } }; diff --git a/packages/types/src/clerk.retheme.ts b/packages/types/src/clerk.retheme.ts index 7a3a3e9b88..6cd8dea7cf 100644 --- a/packages/types/src/clerk.retheme.ts +++ b/packages/types/src/clerk.retheme.ts @@ -498,14 +498,15 @@ export type BuildUrlWithAuthParams = { // TODO: Make sure Isomorphic Clerk navigate can work with the correct type: // (to: string) => Promise -export type CustomNavigation = (to: string) => Promise | void; +export type CustomNavigation = (to: string, options?: NavigateOptions) => Promise | void; export type ClerkThemeOptions = DeepSnakeToCamel>; export interface ClerkOptions { appearance?: Appearance; localization?: LocalizationResource; - navigate?: (to: string) => Promise | unknown; + routerPush?: (to: string) => Promise | unknown; + routerReplace?: (to: string) => Promise | unknown; polling?: boolean; selectInitialSession?: (client: ClientResource) => ActiveSessionResource | null; /** Controls if ClerkJS will load with the standard browser setup using Clerk cookies */ @@ -539,6 +540,10 @@ export interface ClerkOptions { sdkMetadata?: SDKMetadata; } +export interface NavigateOptions { + replace?: boolean; +} + export interface Resources { client: ClientResource; session?: ActiveSessionResource | null;