Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading