Skip to content

Commit cc7fb10

Browse files
authored
Merge pull request #243 from itsmeakhil/perf/lazy-load-heavy-libs
ui
2 parents c10f1de + 7a53d6d commit cc7fb10

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@dnd-kit/sortable": "^10.0.0",
2121
"@dnd-kit/utilities": "^3.2.2",
2222
"@hookform/resolvers": "^3",
23+
"@microsoft/clarity": "^1.0.2",
2324
"@monaco-editor/react": "^4.7.0",
2425
"@peculiar/x509": "^2.0.0",
2526
"@radix-ui/react-accordion": "^1.2.12",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use client"
2+
3+
import { useEffect } from "react"
4+
5+
// Microsoft Clarity heatmaps + session replays. No-op unless
6+
// NEXT_PUBLIC_CLARITY_PROJECT_ID is set (so it stays off in local dev),
7+
// matching how Vercel Analytics only reports in production.
8+
// Data lives in clarity.microsoft.com — nothing touches our backend.
9+
let initialized = false // ponytail: module guard so StrictMode/remounts can't double-inject the script
10+
11+
export function ClarityAnalytics() {
12+
useEffect(() => {
13+
const projectId = process.env.NEXT_PUBLIC_CLARITY_PROJECT_ID
14+
if (!projectId || initialized) return
15+
initialized = true
16+
import("@microsoft/clarity").then((m) => m.default.init(projectId))
17+
}, [])
18+
19+
return null
20+
}

apps/web/src/components/client-shell.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const ClientSpeedInsights = dynamic(
2020
() => import('@vercel/speed-insights/next').then((m) => m.SpeedInsights),
2121
{ ssr: false }
2222
)
23+
const ClientClarity = dynamic(
24+
() => import('@/components/clarity-analytics').then((m) => m.ClarityAnalytics),
25+
{ ssr: false }
26+
)
2327
const ClientToaster = dynamic(
2428
() => import('@/components/branded-toaster').then((m) => m.BrandedToaster),
2529
{ ssr: false }
@@ -47,6 +51,9 @@ export function ClientShell({ children }: Props) {
4751
<Suspense fallback={null}>
4852
<ClientSpeedInsights />
4953
</Suspense>
54+
<Suspense fallback={null}>
55+
<ClientClarity />
56+
</Suspense>
5057
<Suspense fallback={null}>
5158
<ClientToaster />
5259
</Suspense>

0 commit comments

Comments
 (0)