Skip to content

Commit

Permalink
fix(remix): Make clerkState required
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdouvlis committed Feb 18, 2022
1 parent 8f67778 commit df88977
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/remix/src/client/RemixClerkProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export * from '@clerk/clerk-react';
type RemixClerkProviderProps<ClerkStateT extends { __type: 'clerkState' } = any> = {
frontendApi: string;
children: React.ReactNode;
clerkState?: ClerkStateT;
clerkState: ClerkStateT;
} & IsomorphicClerkOptions;

export function ClerkProvider({ children, ...rest }: RemixClerkProviderProps): JSX.Element {
Expand Down
11 changes: 8 additions & 3 deletions packages/remix/src/client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { invalidClerkStatePropError, notUsingSsrWarning } from '../errors';
import { invalidClerkStatePropError, noClerkStateError } from '../errors';
import { ClerkState } from './types';

export function warnForSsr(val: ClerkState | undefined) {
if (!val || !val.__internal_clerk_state) {
console.warn(notUsingSsrWarning);
console.warn(noClerkStateError);
}
}

export function assertValidClerkState(val: any): asserts val is ClerkState | undefined {
export function assertValidClerkState(
val: any,
): asserts val is ClerkState | undefined {
if (!val) {
throw new Error(noClerkStateError);
}
if (!!val && !val.__internal_clerk_state) {
throw new Error(invalidClerkStatePropError);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/remix/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ You're trying to pass an invalid object in "<ClerkProvider clerkState={...}>".
${ssrExample}
`);

export const notUsingSsrWarning = createErrorMessage(`
You installed Clerk in a Remix project, but it looks like you're not taking full advantage of SSR. If you want to enable SSR, try the following:
export const noClerkStateError = createErrorMessage(`
Looks like you didn't pass 'clerkState' to "<ClerkProvider clerkState={...}>".
${ssrExample}
`);
Expand Down

0 comments on commit df88977

Please sign in to comment.