Skip to content

Commit

Permalink
🐛 fix: fix clerk appearance is not applied correctly (lobehub#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctm97 authored and ipoly committed Jul 29, 2024
1 parent c24bf7f commit 0808905
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/layout/AuthProvider/Clerk/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { ClerkProvider } from '@clerk/nextjs';
import { PropsWithChildren, memo, useMemo } from 'react';
import { PropsWithChildren, memo, useEffect, useMemo, useState, useTransition } from 'react';
import { useTranslation } from 'react-i18next';

import UserUpdater from './UserUpdater';
Expand All @@ -15,6 +15,18 @@ const Clerk = memo(({ children }: PropsWithChildren) => {

const localization = useMemo(() => getResourceBundle(language, 'clerk'), [language]);

// When useAppearance returns different result during SSR vs. client-side (when theme mode is auto), the appearance is not applied
// It's because Clerk internally re-applies SSR props after transition which overrides client-side props, see https://github.com/clerk/javascript/blob/main/packages/nextjs/src/app-router/client/ClerkProvider.tsx
// This re-renders the provider after transition to make sure client-side props are always applied
const [, setCount] = useState(0);
const [isPending, startTransition] = useTransition();
useEffect(() => {
if (isPending) return;
startTransition(() => {
setCount((count) => count + 1);
});
}, [isPending, startTransition]);

return (
<ClerkProvider appearance={appearance} localization={localization}>
{children}
Expand Down

0 comments on commit 0808905

Please sign in to comment.