Skip to content

Commit

Permalink
chore(*): Drop export and replace IsomorphicClerkOptions with ClerkPr…
Browse files Browse the repository at this point in the history
…oviderOptionsWrapper
  • Loading branch information
dimkl committed Nov 17, 2023
1 parent 07681fd commit f730233
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 26 deletions.
1 change: 1 addition & 0 deletions packages/expo/src/ClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function ClerkProvider(props: ClerkProviderProps): JSX.Element {
// See JS-598 for additional context.
key={key}
{...rest}
publishableKey={key}
Clerk={buildClerk({ key, tokenCache })}
standardBrowser={!isReactNative()}
>
Expand Down
5 changes: 2 additions & 3 deletions packages/gatsby-plugin-clerk/src/GatsbyClerkProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkProviderProps } from '@clerk/clerk-react';
import {
__internal__setErrorThrowerOptions,
ClerkLoaded,
Expand All @@ -15,9 +15,8 @@ const SDK_METADATA = {
__internal__setErrorThrowerOptions({ packageName: 'gatsby-plugin-clerk' });

export type GatsbyClerkProviderProps = {
children: React.ReactNode;
clerkState: any;
} & IsomorphicClerkOptions;
} & ClerkProviderProps;

export function ClerkProvider({ children, ...rest }: GatsbyClerkProviderProps) {
const { clerkState, ...restProps } = rest;
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/src/app-router/server/ClerkProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
import type { InitialState } from '@clerk/types';
import React from 'react';

import { mergeNextClerkPropsWithEnv } from '../../utils/mergeNextClerkPropsWithEnv';
import { ClientClerkProvider } from '../client/ClerkProvider';
import { initialState } from './auth';

type NextAppClerkProviderProps = React.PropsWithChildren<IsomorphicClerkOptions>;
type NextAppClerkProviderProps = ClerkProviderOptionsWrapper;

export function ClerkProvider(props: NextAppClerkProviderProps) {
const { children, ...rest } = props;
Expand Down
6 changes: 2 additions & 4 deletions packages/nextjs/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type React from 'react';
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';

export type NextClerkProviderProps = {
children: React.ReactNode;
/**
* If set to true, the NextJS middleware will be invoked
* every time the client-side auth state changes (sign-out, sign-in, organization switch etc.).
Expand All @@ -12,4 +10,4 @@ export type NextClerkProviderProps = {
* @default true
*/
__unstable_invokeMiddlewareOnAuthStateChange?: boolean;
} & IsomorphicClerkOptions;
} & ClerkProviderOptionsWrapper;
8 changes: 1 addition & 7 deletions packages/react/src/contexts/ClerkProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { isPublishableKey } from '@clerk/shared/keys';
import type { InitialState } from '@clerk/types';
import React from 'react';

import { multipleClerkProvidersError } from '../errors';
import type { IsomorphicClerkOptions } from '../types';
import type { ClerkProviderProps } from '../types';
import { __internal__setErrorThrowerOptions, errorThrower, withMaxAllowedInstancesGuard } from '../utils';
import { ClerkContextProvider } from './ClerkContextProvider';
import { StructureContext, StructureContextStates } from './StructureContext';
Expand All @@ -12,11 +11,6 @@ __internal__setErrorThrowerOptions({
packageName: '@clerk/clerk-react',
});

export type ClerkProviderProps = IsomorphicClerkOptions & {
children: React.ReactNode;
initialState?: InitialState;
};

function ClerkProviderBase(props: ClerkProviderProps): JSX.Element {
const { initialState, children, ...restIsomorphicClerkOptions } = props;
const { publishableKey = '', Clerk: userInitialisedClerk } = restIsomorphicClerkOptions;
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { ClerkProvider, __internal__setErrorThrowerOptions } from './ClerkProvider';
export type { ClerkProviderProps } from './ClerkProvider';
3 changes: 2 additions & 1 deletion packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type {
BrowserClerk,
ClerkProp,
HeadlessBrowserClerk,
IsomorphicClerkOptions,
ClerkProviderOptionsWrapper,
ClerkProviderProps,
WithClerkProp,
WithSessionProp,
WithUserProp,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class IsomorphicClerk {

constructor(options: IsomorphicClerkOptions) {
const { Clerk = null, publishableKey } = options || {};
this.#publishableKey = publishableKey || '';
this.#publishableKey = publishableKey;
this.#proxyUrl = options?.proxyUrl;
this.#domain = options?.domain;
this.options = options;
Expand Down
22 changes: 21 additions & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ClerkOptions,
ClientResource,
DomainOrProxyUrl,
InitialState,
LoadedClerk,
MultiDomainAndOrProxy,
SDKMetadata,
Expand All @@ -28,9 +29,28 @@ export type IsomorphicClerkOptions = Omit<ClerkOptions, 'isSatellite'> & {
clerkJSVariant?: 'headless' | '';
clerkJSVersion?: string;
sdkMetadata?: SDKMetadata;
publishableKey?: string;
publishableKey: string;
} & MultiDomainAndOrProxy;

export type ClerkProviderProps = IsomorphicClerkOptions & {
children: React.ReactNode;
initialState?: InitialState;
};

// TODO(@dimkl): replacing it with the following make nextjs type tests fail
// `Exclude<IsomorphicClerkOptions, 'publishableKey'> & { publishableKey?: string }`
// find another way to reduce the duplication.
export type ClerkProviderOptionsWrapper = Omit<ClerkOptions, 'isSatellite'> & {
Clerk?: ClerkProp;
clerkJSUrl?: string;
clerkJSVariant?: 'headless' | '';
clerkJSVersion?: string;
sdkMetadata?: SDKMetadata;
publishableKey?: string;
} & MultiDomainAndOrProxy & {
children: React.ReactNode;
};

export interface BrowserClerkConstructor {
new (publishableKey: string, options?: DomainOrProxyUrl): BrowserClerk;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/remix/src/client/RemixClerkProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
import { ClerkProvider as ReactClerkProvider } from '@clerk/clerk-react';
import React from 'react';

Expand All @@ -15,9 +15,8 @@ const SDK_METADATA = {
};

export type RemixClerkProviderProps = {
children: React.ReactNode;
clerkState: ClerkState;
} & IsomorphicClerkOptions;
} & ClerkProviderOptionsWrapper;

/**
* Remix hydration errors should not stop Clerk navigation from working, as the components mount only after
Expand Down
5 changes: 2 additions & 3 deletions packages/remix/src/client/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { IsomorphicClerkOptions } from '@clerk/clerk-react';
import type { ClerkProviderOptionsWrapper } from '@clerk/clerk-react';
import type { InitialState } from '@clerk/types';
import type { PropsWithChildren } from 'react';

export type ClerkState = {
__type: 'clerkState';
Expand All @@ -26,4 +25,4 @@ export type WithClerkState<U = any> = {
clerkState: { __type: 'clerkState' };
};

export type RemixClerkProviderProps = PropsWithChildren<IsomorphicClerkOptions>;
export type RemixClerkProviderProps = ClerkProviderOptionsWrapper;

0 comments on commit f730233

Please sign in to comment.