Skip to content

Commit

Permalink
chore(clerk-js): Apply changes to PathRouter for retheme directory (#…
Browse files Browse the repository at this point in the history
…2222)

* chore(clerk-js): Apply changes to PathRouter for retheme directory

* fix(types): Add NavigationOptions in retheme

---------

Co-authored-by: Dimitris Klouvas <[email protected]>
  • Loading branch information
desiprisg and dimkl authored Nov 28, 2023
1 parent af56f51 commit 950f4b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .changeset/soft-swans-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 4 additions & 3 deletions packages/clerk-js/src/ui.retheme/router/PathRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { NavigateOptions } from '@clerk/types';
import React from 'react';

import { hasUrlInFragment, mergeFragmentIntoUrl, stripOrigin } from '../../utils';
Expand All @@ -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 = () => {
Expand All @@ -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);
}
};
Expand Down
9 changes: 7 additions & 2 deletions packages/types/src/clerk.retheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,15 @@ export type BuildUrlWithAuthParams = {

// TODO: Make sure Isomorphic Clerk navigate can work with the correct type:
// (to: string) => Promise<unknown>
export type CustomNavigation = (to: string) => Promise<unknown> | void;
export type CustomNavigation = (to: string, options?: NavigateOptions) => Promise<unknown> | void;

export type ClerkThemeOptions = DeepSnakeToCamel<DeepPartial<DisplayThemeJSON>>;

export interface ClerkOptions {
appearance?: Appearance;
localization?: LocalizationResource;
navigate?: (to: string) => Promise<unknown> | unknown;
routerPush?: (to: string) => Promise<unknown> | unknown;
routerReplace?: (to: string) => Promise<unknown> | unknown;
polling?: boolean;
selectInitialSession?: (client: ClientResource) => ActiveSessionResource | null;
/** Controls if ClerkJS will load with the standard browser setup using Clerk cookies */
Expand Down Expand Up @@ -539,6 +540,10 @@ export interface ClerkOptions {
sdkMetadata?: SDKMetadata;
}

export interface NavigateOptions {
replace?: boolean;
}

export interface Resources {
client: ClientResource;
session?: ActiveSessionResource | null;
Expand Down

0 comments on commit 950f4b2

Please sign in to comment.