Skip to content

Commit

Permalink
fix(repo): Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
desiprisg committed Nov 15, 2023
1 parent 4bfe7b6 commit 265a880
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 83 deletions.
5 changes: 2 additions & 3 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
HandleOAuthCallbackParams,
InstanceType,
ListenerCallback,
OrganizationListProps,
NavigateOptions, OrganizationListProps,
OrganizationProfileProps,
OrganizationResource,
OrganizationSwitcherProps,
Expand All @@ -50,8 +50,7 @@ import type {
UnsubscribeCallback,
UserButtonProps,
UserProfileProps,
UserResource,
} from '@clerk/types';
UserResource } from '@clerk/types';

import type { MountComponentRenderer } from '~ui/Components';

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-clerk/src/GatsbyClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function ClerkProvider({ children, ...rest }: GatsbyClerkProviderProps) {
return (
<ReactClerkProvider
push={to => navigate(to)}
replace={to => navigate(to, { replace: true })}
initialState={__clerk_ssr_state || {}}
sdkMetadata={SDK_METADATA}
{...restProps}
Expand Down
71 changes: 0 additions & 71 deletions packages/nextjs/src/app-beta/client/ClerkProvider.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/nextjs/src/app-router/client/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ClientClerkProvider = (props: NextClerkProviderProps) => {
};
}, []);

const mergedProps = mergeNextClerkPropsWithEnv({ ...props, push: navigate });
const mergedProps = mergeNextClerkPropsWithEnv({ ...props, push: navigate, replace: to => router.replace(to) });
return (
<ClerkNextOptionsProvider options={mergedProps}>
{/*// @ts-ignore*/}
Expand Down
15 changes: 9 additions & 6 deletions packages/nextjs/src/app-router/client/useAwaitableNavigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { useCallback, useEffect } from 'react';

type NavigateFunction = ReturnType<typeof useRouter>['push'];

declare global {
interface Window {
__clerk_nav_ref: (to: string) => any;
__clerk_nav_ref: NavigateFunction;
__clerk_nav_resolves_ref: Array<(val?: any) => any> | undefined;
}
}
Expand All @@ -15,13 +17,14 @@ export const useAwaitableNavigate = () => {
const { push } = useRouter();
const pathname = usePathname();
const params = useSearchParams();
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands

const urlKey = pathname + params.toString();

useEffect(() => {
window.__clerk_nav_ref = (to: string) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
window.__clerk_nav_ref = (to, opts) => {
if (to === window.location.href.replace(window.location.origin, '')) {
push(to);
push(to, opts);
return Promise.resolve();
}

Expand All @@ -43,7 +46,7 @@ export const useAwaitableNavigate = () => {
window.__clerk_nav_resolves_ref = [];
});

return useCallback((to: string) => {
return window.__clerk_nav_ref(to);
return useCallback<NavigateFunction>((to, opts) => {
return window.__clerk_nav_ref(to, opts);
}, []);
};
1 change: 1 addition & 0 deletions packages/remix/src/client/RemixClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function ClerkProvider({ children, ...rest }: RemixClerkProviderProps): J
<ClerkRemixOptionsProvider options={mergedProps}>
<ReactClerkProvider
push={(to: string) => awaitableNavigateRef.current?.(to)}
replace={(to: string) => awaitableNavigateRef.current?.(to, { replace: true })}
initialState={__clerk_ssr_state}
sdkMetadata={SDK_METADATA}
{...mergedProps}
Expand Down
5 changes: 3 additions & 2 deletions packages/remix/src/client/useAwaitableNavigate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useLocation, useNavigate } from '@remix-run/react';
import React from 'react';
import type { NavigateOptions } from 'react-router';

type Resolve = (value?: unknown) => void;

Expand All @@ -18,10 +19,10 @@ export const useAwaitableNavigate = () => {
resolveAll();
}, [location]);

return (to: string) => {
return (to: string, opts?: NavigateOptions) => {
return new Promise(res => {
resolveFunctionsRef.current.push(res);
navigate(to);
navigate(to, opts);
});
};
};
1 change: 1 addition & 0 deletions playground/vite-react-ts/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function ClerkProviderWithRoutes() {
<ClerkProvider
publishableKey={clerkPubKey}
push={to => navigate(to)}
replace={to => navigate(to, {replace: true} )}
>
<div>
<a href='#'>
Expand Down

0 comments on commit 265a880

Please sign in to comment.