Skip to content

Commit

Permalink
Add browserOnly to posthog config
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjdominguez committed May 22, 2024
1 parent 5955251 commit b22ff41
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/theme/DocRoot/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DocRootLayoutMain from '@theme/DocRoot/Layout/Main';
import styles from './styles.module.css';
import BrowserOnly from '@docusaurus/BrowserOnly';
import { AiChatBot } from '@site/src/components/AiChatBot/AiChatBot';
import UserFetcher from './posthogConfig';
import UserFetcherWrapper from './posthogConfig';

export default function DocRootLayout({ children }) {
const sidebar = useDocsSidebar();
Expand All @@ -15,7 +15,7 @@ export default function DocRootLayout({ children }) {

return (
<div className={styles.docsWrapper}>
<UserFetcher />
<UserFetcherWrapper />
<BackToTopButton />
<div className={styles.docRoot}>
{sidebar && (
Expand Down
7 changes: 6 additions & 1 deletion src/theme/DocRoot/Layout/posthogConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import posthog from 'posthog-js';
import BrowserOnly from '@docusaurus/BrowserOnly';

// 🦔 config
posthog.init('phc_MZpdcQLGf57lyfOUT0XA93R3jaCxGsqftVt4iI4MyUY', {
Expand Down Expand Up @@ -47,7 +48,7 @@ async function fetchUser() {
}
}

export default function UserFetcher() {
function UserFetcher() {
const [docsUser, setDocsUser] = useState(null);

useEffect(() => {
Expand All @@ -64,3 +65,7 @@ export default function UserFetcher() {

return null;
}

export default function UserFetcherWrapper() {
return <BrowserOnly fallback={<div>Loading...</div>}>{() => <UserFetcher />}</BrowserOnly>;
}

0 comments on commit b22ff41

Please sign in to comment.