Skip to content

Commit 34d9bff

Browse files
committed
chore: isolate fathom-script into client component + fix reliability of the pathname
1 parent 7a5de77 commit 34d9bff

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

apps/web/app/layout.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ThemeModeScript } from "flowbite-react";
22
import { Inter as InterFont } from "next/font/google";
3-
import { headers } from "next/headers";
4-
import type { Metadata, NextPage, Viewport } from "next/types";
5-
import type { FC, PropsWithChildren } from "react";
3+
import type { Metadata, Viewport } from "next/types";
4+
import type { PropsWithChildren } from "react";
5+
import { FathomScript } from "~/components/fathom-script";
66

77
import "~/styles/globals.css";
88

@@ -54,25 +54,16 @@ export const viewport: Viewport = {
5454
],
5555
};
5656

57-
const RootLayout: NextPage<PropsWithChildren> = ({ children }) => {
58-
const pathname = headers().get("next-url");
59-
const isExamplesPage = pathname?.startsWith("/examples/");
60-
57+
export default function RootLayout({ children }: PropsWithChildren) {
6158
return (
6259
<html lang="en" className={`${interFont.variable} font-sans`}>
6360
<head>
6461
<ThemeModeScript />
6562
</head>
6663
<body className="bg-white text-gray-600 antialiased dark:bg-gray-900 dark:text-gray-400">
6764
{children}
68-
{!isExamplesPage && <FathomScript />}
65+
<FathomScript />
6966
</body>
7067
</html>
7168
);
72-
};
73-
74-
const FathomScript: FC = () => {
75-
return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
76-
};
77-
78-
export default RootLayout;
69+
}

apps/web/components/fathom-script.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"use client";
2+
3+
import { usePathname } from "next/navigation";
4+
5+
export function FathomScript() {
6+
const pathname = usePathname();
7+
const isExamplesPage = pathname.startsWith("/examples/");
8+
9+
if (isExamplesPage) return null;
10+
11+
return <script data-site="UXMSXUQI" defer src="https://cdn.usefathom.com/script.js" />;
12+
}

0 commit comments

Comments
 (0)