Skip to content

Commit

Permalink
Merge pull request #2400 from invoiceninja/GH-2393
Browse files Browse the repository at this point in the history
Dynamically load Google module
  • Loading branch information
beganovich authored Mar 5, 2025
2 parents 70c96e9 + 4695a26 commit c8d5876
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/GoogleOAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@
*/

import { isHosted } from '$app/common/helpers';
import { GoogleOAuthProvider } from '@react-oauth/google';
import { ReactNode } from 'react';
import { ReactNode, Suspense, lazy } from 'react';

const GoogleOAuthProvider = lazy(() =>
import('@react-oauth/google').then((module) => ({
default: module.GoogleOAuthProvider,
}))
);

export function GoogleOAuth({ children }: { children: ReactNode }) {
const googleClientId = import.meta.env.VITE_GOOGLE_CLIENT_ID;

return isHosted() ? (
<GoogleOAuthProvider clientId={googleClientId}>
{children}
</GoogleOAuthProvider>
) : (
<>{children}</>
if (!isHosted()) {
return <>{children}</>;
}

return (
<Suspense fallback={<>{children}</>}>
<GoogleOAuthProvider clientId={googleClientId}>
{children}
</GoogleOAuthProvider>
</Suspense>
);
}

0 comments on commit c8d5876

Please sign in to comment.